CSV File
CSV (Comma Separated Values) is a simple file format
used to store data in tabular form such as excel sheet or database. Each line of the file is a data record.
Each record consists of one or more fields, separated by commas. The csv module is used for working with CSV files in python. It is
used to read and write tabular data in CSV format.
name,class, marks
ajay,12,75
vijay,11,85
then save the file named as"abc.csv"
# reading csv file contents
import csv
f=open("abc.csv",'r')
r=csv.reader(f) # canvert file object into reader object
for row in r:
print(row)
Every record is stored in reader object in form of List
2.
3.
join() is string method that join all values of each row with comma separator
4.
5.
6.
7.
8
Contents of student.csv file
name,class, marks
Vinod,12,75
Vijay,11,85
Sunil,12,65
Mukesh,10,75
Rajat,10,85
Kamal,12,70
Amit,11,95
No comments:
Post a Comment