wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Revision - CSV File Handling

Total questions: 15

Worksheet time: 3mins

Name
Class
Date
1.

Rashil is working on a project that involves analyzing sales data stored in a CSV file. Which Python module should he primarily use for handling these CSV files?

a)

csv

b)

txt

c)

xml

d)

json

2.

Reyansh is working on a project where he needs to save the results of his experiments in a structured format. He decides to use a CSV file for this purpose. What does the csv.writer() function do?

a)

It reads data from a CSV file.

b)

It converts CSV data to JSON format.

c)

It writes data to a CSV file.

d)

It deletes data from a CSV file.

3.

During a class project, Shaurya needs to write a single row of data to a CSV file using the csv.writer method. Which method should he use?

a)

writerow()

b)

insert_row()

c)

addrow()

d)

writerows()

4.

Taran is working on a project that involves reading and writing CSV files. He comes across the newline='' argument in the open() function. What does this argument do when working with CSV files?

a)

It determines the delimiter used in the CSV file.

b)

It prevents the addition of extra newline characters when reading or writing CSV files.

c)

It adds extra newline characters when reading CSV files.

d)

It specifies the encoding type for the CSV file.

5.

What happens if the CSV file being read by Reyansh contains inconsistent row lengths?

a)

All rows will be padded with empty values to match the longest row.

b)

The CSV file will be ignored entirely if row lengths are inconsistent.

c)

Inconsistent row lengths are automatically corrected during the read process.

d)

Inconsistent row lengths can cause errors or misalignment in data when reading a CSV file.

6.

During a class project, Reyansh and Tanisha were discussing how to handle data files. They wondered what the default delimiter is when using the csv module in Python.

a)

;

b)

,

c)

|

d)

tab

7.

During a school project, Reyansh, Taran, and Tanisha need to save their data into a CSV file. Which method should they use to write multiple rows in one call?

a)

writeall()

b)

bulkInsert()

c)

addRows()

d)

writerows()

8.

Abhishek and Adivya are working on a project that involves reading data from a CSV file. They need to skip the header row to process the data correctly. How can they achieve this?

a)

Set skip_header=True in csv.reader()

b)

Use next() before iterating over rows

c)

Both a and b

d)

Use csv.Sniffer() to detect headers

9.

When Adivya was trying to analyze the sales data, she opened a CSV file using the (a)   mode to read the file.

10.

During a group project, Abhishek and Tanisha decided to create a CSV file to organize their data. They realized that a CSV file can use characters other than commas, such as ; or |, as delimiters, which can be specified using the (a)   parameter in both csv.reader and csv.writer.

11.

While working on a group project, Adivya wanted to ensure that a file is properly closed after it is processed. To achieve this, she used the (a)   statement in Python.

12.

Abhishek and Taran are working on a project that requires them to save data in a CSV file. They need to write a header row to the CSV file in Python without using DictWriter. How can they achieve this?

a)

Use the header argument in csv.writer() while writing rows.

b)

Write the header manually without using any library.

c)

Use open() and write() methods to create the header line.

d)

Use csv.writer() and call writerow() with the list of headers.

13.

What is the role of next() when Rashil is working with CSV files in Python?

a)

next() is used to convert CSV data into a dictionary.

b)

next() is used to read the entire CSV file at once.

c)

next() is used to skip the header row in CSV files.

d)

next() is used to write data to a new CSV file.

14.

Taran and Tanisha are discussing different file formats in Python for their data science project. They wonder what is a similarity between text files and CSV files.

a)

Both can only be read using the csv module.

b)

Both store data in plain text format.

c)

Both require a specific delimiter to separate data.

d)

Both are binary files by default.

15.

While working on a group project, Abhishek and Tanisha are reading a CSV file containing data about their survey results. They want to skip the header row to directly access the data. Which of the following is the correct way to use next() to skip the header row while reading the CSV file in Python?

a)

next(csv.reader(file))

b)

reader = csv.reader(file)

reader.next()

c)

reader = csv.reader(file)

next(reader)

d)

reader = csv.reader(file)

csv.next(reader)