CSV file assignment using Python
CSV file assignment using Python is meant for computer science students. This CSV file assignment contains the basic operations that we can perform on CSV file like creating a CSV file, reading a csv file, deleting a record from CSV file and updating CSV file.
Q1. suppose a CSV file ‘student.csv’ is already available to you with the following records. write a python program to read this csv file and display its contents on the screen.
Rollno,name,class,stream,agg,percenrage,result
1,ramji,12B,SCIENCE,484,96.8,PASS
2,anuj,11A,COMM,452,90.4,PASS
3,ujjwal,12C,HUMAN,385,77,PASS
4,shlok,11B,SCIENCE,490,98,PASS
5,nipun,11A,COMM,347,69.4,PASS
6,arushi,12C,COMM,456,91.2,PASS
7,ayushi,11B,HUMAN,345,69,PASS
8,sehaj,12A,SCIENCE,421,84.2,PASS
9,swarnima,12A,SCIENCE,345,69,PASS
10,harsh,11C,HUMAN,455,91,PASS
reading a csv file in python
import csv file = open('student.csv','r') data = csv.reader(file) for record in data: print(record) file.close()
Q2. Write a Python program to create a CSV file ‘student.csv’ for the following data
admno | name | class | section |
---|---|---|---|
101 | rakesh | 10 | D |
102 | swarnima | 12 | A |
103 | Samriddhi | 5 | B |
104 | ujjwal | 11 | D |