How can I read only the header column of a CSV file using Python?

后端 未结 9 720
生来不讨喜
生来不讨喜 2020-12-14 10:05

I am looking for a a way to read just the header row of a large number of large CSV files.

Using Pandas, I have this method available, for each csv file:

         


        
9条回答
  •  天命终不由人
    2020-12-14 10:40

    Here's one way. You get 1 row.

    In [9]: DataFrame(np.random.randn(10,4),columns=list('abcd')).to_csv('test.csv',mode='w')
    
    In [10]: read_csv('test.csv',index_col=0,nrows=1)
    Out[10]: 
              a         b         c         d
    0  0.365453  0.633631 -1.917368 -1.996505
    

提交回复
热议问题