pandas 在表中读取而没有标题 [英] Pandas read in table without headers
本文介绍了 pandas 在表中读取而没有标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何使用熊猫读取.csv文件(没有标题),并且只需要一部分列(例如总共20列中的第4和第7),如何读取?我似乎无法执行usecols
How can I read in a .csv file (with no headers) and when I only want a subset of the columns (say 4th and 7th out of a total of 20 columns), using pandas? I cannot seem to be able to do usecols
推荐答案
为了读取没有头的csv,仅对于某些列,您需要将参数header=None
和usecols=[3,6]
传递给第4列和第7列:
In order to read a csv in that doesn't have a header and for only certain columns you need to pass params header=None
and usecols=[3,6]
for the 4th and 7th columns:
df = pd.read_csv(file_path, header=None, usecols=[3,6])
请参见文档
这篇关于 pandas 在表中读取而没有标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文