Csv Files
Csv Files
Csv Files
myfile.cs
OUTP AFTER v
UT EXECUTION
EXAMPLE PROGRAM TO WRITE ON TO THE CSV FILE
import csv
fields=['Rno','Name','Avg']
rows=[ ['1', 'Abhishek' , '98'],
Content of Student.csv
['2', 'Anand', '99'], Rno,Name,Avg
['3', 'Ravi', '88']]
1,Abhishek,98
with open("Student.csv","w") as fout:
csvwriter=csv.writer(fout) 2,Anand,99
csvwriter.writerow(fields)
3,Ravi,88
print("Column headings written")
csvwriter.writerows(rows)
EXAMPLE PROGRAM FOR WRITING ON TO THE FILE
EXAMPLE PROGRAM FOR WRITING ON TO THE FILE
myfile.
csv
Example : Counting number
of records
myfile.cs
Example : Sum of Salary and
counting employee getting
more than 70000
Example : Sum of Salary and
counting employee getting
more than 70000
myfile.cs
v
CHANGING THE DELIMITER
def readstudent():
with open("Student.csv") as fin:
reader=csv.reader(fin, delimiter='/')
for row in reader:
print(row)
readstudent()
OUTPUT:
France
Italy
Spain
Russia
India
EXAMPLE PROGRAM USING DICTREADER
• Write a python program to read from the file
emp.csv and display the name of the employees
whose salary >50000