pandas 在没有标题的表中读取 [英] Pandas read in table without headers

查看:28
本文介绍了 pandas 在没有标题的表中读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我只想要列的子集(比如总共 20 列中的第 4 和第 7 列)时,如何使用 Pandas 读取 .csv 文件(没有标题)?我似乎无法做到 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=Noneusecols=[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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆