0% found this document useful (0 votes)
93 views3 pages

CS-12-File Handling (CSV File)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 3

Subject: Computer Science

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

MCQ on Basic Concept of CSV File


Name of the Vidyalaya:________________________________________________________________
Name of the Student :________________________Class & Sec:______________Roll No:______

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.The full line of the file as a string


B.The row data as a list
C.The individual value data that is separated by the delimiter
D.The column data as a list
Q.5. Which of the following is the correct way to open the CSV file hrdata.csv for
reading using the pandas package? Assume that the pandas package has already
been imported.

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:______

Q.1. What is a CSV file


Q.2. How to parse CSV files in Python using the builtin library csv
Q.3. How to parse CSV files in Python using the pandas package
Q.4. What is the advantage of CSV File?
Q.5. How to close CSV file using close() function.?

Worksheet-3

(Practical Based Questions)


Name of the Vidyalaya:________________________________________________________________
Name of the Student :________________________Class & Sec:______________Roll No:______

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.

You might also like