Is it possible to use read_csv to read only specific lines?

前端 未结 4 601
天涯浪人
天涯浪人 2021-01-02 14:00

I have a csv file that looks like this:

TEST  
2012-05-01 00:00:00.203 ON 1  
2012-05-01 00:00:11.203 OFF 0  
2012-05-01 00:00:22.203 ON 1  
2012-05-01 00:00         


        
4条回答
  •  春和景丽
    2021-01-02 14:46

    from cStringIO import StringIO
    import pandas
    
    s = StringIO()
    with open('file.csv') as f:
        for line in f:
            if not line.startswith('TEST'):
                s.write(line)
    s.seek(0) # "rewind" to the beginning of the StringIO object
    
    pandas.read_csv(s) # with further parameters…
    

提交回复
热议问题