CSV New
CSV New
CSV New
The structure of a CSV file is given away by its name. Normally, CSV files use a
comma to separate each specific data value. Here’s what that structure looks like:
In general, the separator character is called a delimiter, and the comma is not the only
one used. Other popular delimiters include the tab (\t), colon (:) and semi-colon (;)
characters. Properly parsing a CSV file requires us to know which delimiter is being
used.
CSV files are very easy to work with programmatically. Any language that supports
text file input and string manipulation (like Python) can work with CSV files directly.
The csv module’s reader and writer objects read and write sequences.
Programmers can also read and write data in dictionary form using
the DictReader and DictWriter classes. Each row read from the csv file is
returned as a list of strings.
reader() Return a reader object which will iterate over lines in the
given csvfile. csvfile can be any object which supports the iterator protocol and
returns a string— file objects and list objects are both suitable. Each row read
from the csv file is returned as a list of strings. No automatic data type
conversion is performed.
# field names
fields = ['Name', 'Branch', 'Year', 'CGPA']
def SearchRecord( ):
with open ("data1.csv","r",newline="") as f:
dread=csv.reader(f,delimiter=",")
c=0
for r in dread:
if c==0: #To print Header row
print(r)
else:
if int(r[2])>=90:#String need to be Converted
print(r)
c=c+1
print(dread.line_num)#returns number of lines read