Prevent pandas read_csv treating first row as header of column names

前端 未结 2 1781
轻奢々
轻奢々 2020-11-28 15:13

I\'m reading in a pandas DataFrame using pd.read_csv. I want to keep the first row as data, however it keeps getting converted to column names.

2条回答
  •  旧巷少年郎
    2020-11-28 15:35

    I think you need parameter header=None to read_csv:

    Sample:

    import pandas as pd
    from pandas.compat import StringIO
    
    temp=u"""a,b
    2,1
    1,1"""
    
    df = pd.read_csv(StringIO(temp),header=None)
    print (df)
       0  1
    0  a  b
    1  2  1
    2  1  1
    

提交回复
热议问题