CSV FILE PROGRAMS
1. Write a program to store student data (Roll No, Name, Class) of 5 students in a
CSV file named [Link].
2. Write a Python program to input item details (Item ID, Item Name, Price) and write
them to a file [Link] using the writerow() method.
3. Given a list of employees with (EmpID, Name, Salary), write a function to save all
employee details into a CSV file called [Link].
4. Accept movie details from the user (Movie ID, Title, Genre) and store them into
[Link] file, with each movie on a new row.
5. Write a program to create a CSV file [Link] and write at least 4 book records
using a writer object.
6. Write a Python program to read and display all records from a file named
[Link].
7. Read the file [Link] and display only those items whose price is greater
than 500.
8. Write a program to read data from [Link] and display each employee's
name with their salary.
9. From a CSV file [Link], read all movies and count how many are of the
genre ‘Comedy’.
10. Write a function that reads a file [Link] and displays books whose name
starts with the letter ‘A’.
11. Read data from [Link], add a new record, and save the updated content
into a new file updated_students.csv.
12. Write a Python program to copy contents from [Link] into
backup_items.csv.
13. Read all records from [Link], increase the salary by 10% for each
employee, and write the updated records to updated_employees.csv.
14. Read data from [Link], and remove all books with price less than 100. Write
the filtered data to books_new.csv.
15. Read from [Link] and create a new file short_movies.csv containing only
the movies whose title has less than 10 characters.
16. Given a code snippet that writes to a CSV file using [Link], predict the output
file content.
CSV File ([Link])
RollNo,Name,Class
101,Amit,12
102,Neha,12
103,Rahul,12
Python Code:
import csv
with open("[Link]", "r") as f:
reader = [Link](f)
for row in reader:
print(" | ".join(row))
17. Identify and correct errors in the following code snippet for reading data from a CSV file.
18. What will be the output of the following code if the file [Link] contains... (followed by
given content)?
[Link]
BookID,Title,Price
1,Python Basics,300
2,AI Guide,500
3,Algo,200
Code:
import csv
with open("[Link]", "r") as file:
reader = [Link](file)
next(reader)
for row in reader:
if int(row[0]) % 2 == 1:
print(row[1])
19. Fill in the blanks to complete a program that reads from [Link] and writes selected
records to filtered_books.csv.
20. Write a program that allows a user to enter multiple contact records (Name, Phone, Email)
and search for a record by name from the [Link] file.
21. Create a CSV file [Link] with fields (Roll No, Name, Marks in 5 subjects), and
calculate the total and average marks for each student after reading.
22. Read from [Link], and write only those records to [Link] where average is
more than 40.
23. Write a program that reads from [Link] and prints the total number of
contacts with Gmail IDs.