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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -