FILE HANDLING
Class 12_CSc
How to iterate through a CSV file in Python?
• csvreader is an iterable object. Hence, .next () method
returns the current row and advances the iterator to the next row.
• Since the first row of our csv file contains the headers (or field
names), we save them in a list called fields. Now, we iterate through
remaining rows using a for loop. Each row is appended to a list
called rows.
FILE HANDLING
Class 12_CSc
1.Store the Country name, gold, silver and bronze medals won by 5
different countries in Asianic Games using CSV file. Read the file and
print the content in the alphabetical order of country names in a neat
format
FILE HANDLING
Class 12_CSc
FILE HANDLING
Class 12_CSc
Write a function Create_csv() to store the city_name and rainfall
during a month of 5 cities in “rainfall.csv” and another function
Max_rainfall() to read the file and print the name of the city that
received the highest rainfall.
FILE HANDLING
Class 12_CSc
FILE HANDLING
Class 12_CSc
FILE HANDLING
Class 12_CSc
Q1.Write a python program to write the following into a csv file
named employee.csv with comma as delimiter and read it as a list.Also
find the total salary. Structure of the record is
employeeno,name,mobileno,salary and commission
Q2. Write a program to add/insert records in file “data.csv”. Structure of
a record is roll number, name , class and marks. Find the minimum
marks

CSC_Term1_21.07.21_csv3.pptx ppt for compter science

  • 1.
    FILE HANDLING Class 12_CSc Howto iterate through a CSV file in Python? • csvreader is an iterable object. Hence, .next () method returns the current row and advances the iterator to the next row. • Since the first row of our csv file contains the headers (or field names), we save them in a list called fields. Now, we iterate through remaining rows using a for loop. Each row is appended to a list called rows.
  • 2.
    FILE HANDLING Class 12_CSc 1.Storethe Country name, gold, silver and bronze medals won by 5 different countries in Asianic Games using CSV file. Read the file and print the content in the alphabetical order of country names in a neat format
  • 3.
  • 4.
    FILE HANDLING Class 12_CSc Writea function Create_csv() to store the city_name and rainfall during a month of 5 cities in “rainfall.csv” and another function Max_rainfall() to read the file and print the name of the city that received the highest rainfall.
  • 5.
  • 6.
  • 7.
    FILE HANDLING Class 12_CSc Q1.Writea python program to write the following into a csv file named employee.csv with comma as delimiter and read it as a list.Also find the total salary. Structure of the record is employeeno,name,mobileno,salary and commission Q2. Write a program to add/insert records in file “data.csv”. Structure of a record is roll number, name , class and marks. Find the minimum marks