parsing - reading header in python from csv -
is there way inject header array header vector in more efficient way without using packages such csv, pandas, etc...?
data = [] b = 1 open(datafile, "rb") f: line in f: if b: header=line.strip('\n').split(',') b = 0 continue entries=line.strip('\n').split(',') data.append(dict(zip(header,entries))) #print data return data
if don't need go through same file twice, yielding values better returning list.
with open(datafile, "rb") f: header = next(f).strip('\n').split(',') line in f: entry=line.strip('\n').split(',') yield dict(zip(header,entry))
Comments
Post a Comment