DIFFERENT TYPES OF CSV FILE PYTHON PROGRAMS :
- PYTHON PROGRAM TO RECORD STUDENT DETAILS IN CSV FILE
Q WRITE A PYTHON PROGRAM TO CREATE A CSV FILE AND TO STORE NAME, ROLL NUMBER, STANDARD, DIVISION AND CGPA OF A STUDENT.
CODE FOR THE ABOVE PYTHON PROGRAM :
WRITTEN CODE FOR THE ABOVE PROGRAM :
import csv
fields = ['Name','RollNo','Std','Div','CGPA',]
rows = [['NIKHIL','12','7','A','9.0'],
['SANCHIT','23','8','B','9.1'],
['ADITYA' ,'35','6','E','9.3'],
['SAGAR' ,'24','8','A','9.1'],
['PRATEEK','15','7','C','7.8'],
['SAHIL' ,'40','9','D','9.1']]
filename = "Students_records.csv"
with open(filename,'w')as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow(fields)
csvwriter.writerows(rows)
OUTPUT :
NOTE : This CSV file python program prints the give value in the file "Students_records.csv". The program will automatically open the file and print the details give in the program. to check the details, you have to search the file named "Students_records" and open it. you will get the same output as given below. please make sure that (python would not open the csv file by itself, you have to search it in your computer search bar. )