Ignore character while importing with pandas

前端 未结 4 1200
刺人心
刺人心 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:34

    I have the same problem. My first line is

    # id x y ...
    

    So pandas header keyword doesn't work. I did the following by reading it twice:

    cos_phot_header = pd.read_csv(table, delim_whitespace=True, header=None, engine='python', nrows=1)
    cos_plot_text_header = cos_phot_header.drop(0, axis=1).values.tolist()
    cos_phot_data = pd.read_csv(table, skip_blank_lines=True, comment='#', 
                   delim_whitespace=True, header=None, engine='python', names=cos_plot_text_header[0])
    

    I don't understand why there is no such option in pandas to do this, it is a very common problem that everyone encounters. You can also read the table with no lines (nrows=0) and use .columns, but honestly I think it is an equally ugly solution to the problem.

提交回复
热议问题