Thursday, 12 September 2013

Use DictReader in Python to determine table header in CSV file

Use DictReader in Python to determine table header in CSV file

I am using DictReader to convert a csv table into a dict. However the csv
file contains some lines above the data I need. I could use next(), but
thats not an intelligent solution as the number of "junk" lines may vary.
e.g. The file is as follows:
#stuff not needed
#more stuff which is not needed
label,path,value
a,/path,1
b,/path,2
So can I automatically extract the table and the header in this case ?

No comments:

Post a Comment