ajwood
ajwood

Reputation: 19027

Getting csv header in pandas from arbitrary row

I have a csv that looks like this:

s,k,i,p   # 0. N rows to skip
H,E,A,D   # 1. header names
n,o,n,e   # 2. N more rows to skip
1,2,3,4   # 3. Data
6,7,8,9   # 4. ...
...       # 5. ...

Can I read this data in with a single call to pandas.read_csv? I'm having trouble because I can't seem to skip rows until the header then skip more rows until the data

Upvotes: 2

Views: 65

Answers (1)

Mr.F
Mr.F

Reputation: 936

you can pass a list of rows to skip to skiprows like so:

In [2]:pd.read_csv('the_file.csv', skiprows=[0,2])
Out[2]:
   H  E  A  D
0  1  2  3  4
1  6  7  8  9

Upvotes: 3

Related Questions