Ignore character while importing with pandas

前端 未结 4 1201
刺人心
刺人心 2021-01-16 19:52

I could not find such an option in the documentation. A measuring device spits out everything in Excel:

    <>         


        
4条回答
  •  不知归路
    2021-01-16 20:22

    I have the same problem. My first line is:

    # id ra dec ...
    

    Where # is the commenting-character in Python. import_csv thinks that # is a column header, but it's not. The workaround I used was to define the headers manually:

    headerlist = ['id', 'ra', 'dec', ...]  
    df = pd.read_csv('data.txt', index_col=False, header=0, names=headerlist)
    

    Note that index_col is optional in regards to this problem.

    If there is any option to ignore a certain character in header line, I haven't found it. Hope this solution can be improved upon.

提交回复
热议问题