CS-12-File Handling (CSV File)
CS-12-File Handling (CSV File)
CS-12-File Handling (CSV File)
Class: XII
Unit: File Handling Lesson: CSV File No of session required: 1
Session Gist of Lesson Expected Teaching Learning Suggested Assessment strategies Worksheets
Learning activities planned materials/Reso planned/Assignment/Practical
Outcomes/ urces
ELO
01 CSV File : Students At least 15-20 minutes Students import csv
Import csv module, will be able talk on the topic should be #csv file writing code Worksheet 1
Functions- to INSTRUCTIONS: with open('d:\\a.csv','w') as newFile:
advised to
Open/Close a csv file, understand CSV File characteristic newFileWriter = csv.writer(newFile) (MCQ Based
Read from a csv file how to *One line for each record see these newFileWriter.writerow(['user_id','bene questions)
and Write into a csv import * Comma separated fields video ficiary'])
file using csv. module When use CSV ? newFileWriter.writerow([1,'xyz']) Worksheet 2
reader() and csv. and read *When data has a strict newFileWriter.writerow([2,'pqr'])
writerow() and write tabular structure link for PPTs: newFile.close()
Short Answer
file *To transfer large https:// #csv file reading code Questions
database between drive.google.com with open('d:\\a.csv','r') as newFile:
/drive/my-drive Worksheet 3
program newFileReader = csv.reader(newFile)
for row in newFileReader: (Practical
https://youtu.be/ print (row) Based
klLHeZHsapk newFile.close() Questions)
Link for lab activity:
https://youtu.be/4ZnE3N140Xk
Worksheet-1
Q.1. In regards to separated value files such as .csv and .tsv, what is the delimiter?
A. Any character such as the comma (,) or tab (\t) that is used to separate
the column data.
B. Delimiters are not used in separated value files
C. Anywhere the comma (,) character is used in the file
D. Any character such as the comma (,) or tab (\t) that is used to separate
the row data
Q.2. In separated value files such as .csv and .tsv, what does the first row in the file
typically contain?
A. The author of the table data
B. The source of the data
C. Notes about the table data
D. The column names of the data
Q.3. Assume you have a file object my_data which has properly opened a separated
value file that uses the tab character (\t) as the delimiter.
What is the proper way to open the file using the Python csv module and assign it
to the variable csv_reader?
Assume that csv has already been imported.
A.csv.tab_reader(my_data)
B.csv.reader(my_data)
C.csv.reader(my_data, delimiter='\t')
D.csv.reader(my_data, tab_delimited=True)
Q.4. When iterating over an object returned from csv.reader(), what is returned with
each iteration? For example, given the following code block that assumes
csv_reader is an object returned from csv.reader(), what would be printed to the
console with each iteration? for item in csv_reader: print(item)
A.pandas.open_csv('hrdata.csv', 'r')
B.pandas.open('hrdata.csv','r')
C.pandas.read_csv('hrdata.csv')
D.pandas.read_table('hrdata.csv')
Worksheet-2
CSV File (Short Answer Questions)
Name of the Vidyalaya:____________________________________________________________
Name of the Student :________________________Class & Sec:______________Roll No:______
Worksheet-3
Q.1. Write a Python program to read each row from a given csv file and print a list of
strings.
Q.2. Write a Python program to read a given CSV file having tab delimiter
Write a Python program to write a Python list of lists to a csv file. After writing the
Q.3. CSV file read the CSV file and display the content.