Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

CS-12-File Handling (CSV File)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 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)
Read from a csv file how to *One line for each record see these newFileWriter.writerow(['user_id','benefi (MCQ Based
and Write into a csv import * Comma separated fields video ciary']) questions)
file using csv. reader() module When use CSV ? newFileWriter.writerow([1,'xyz'])
and csv. writerow() and read *When data has a strict newFileWriter.writerow([2,'pq Worksheet 2
and write tabular structure lr']) #csv file reading code Short Answer
file *To transfer large newFile.close() with open('d:\\a.csv','r') as newFile: Questions
database between ink for PPTs: newFileReader = csv.reader(newFile)
program https://drive.goo for row in newFileReader:
print (row) Worksheet 3
gle.com/drive/m
https://youtu.be/klLH y-drive newFile.close() (Practical
eZHsapk Based
Link for lab activity: Questions)
https://youtu.be/4ZnE3N140Xk
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')
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.?

(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