python - Complicated csv format: columns in two lines -
the following (what believe be) awkward header of file diving right now:
,,,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012 "office","office(code)","origin" "albania","al","total",,,,,,,,,,,,,,,,,,,,,6,49,87,201,390,395,116,420,541,402,349,21,,
that is, first 2 lines together constitute headers. there way apply read_csv()
without major hassle?
you parse first 2 lines manually, pass rest on read_csv
, i.e. like:
with open('data.csv') f: headers = f.readline().strip().split(',') # years headers[:3] = f.readline().strip().split(',') # update first 3 columns data = pd.read_csv(f, names=headers)
note pass file handle f
read_csv
"read head" @ start of third line.
Comments
Post a Comment