如何使用pandas从csv中读取特定的列索引

W.A*_*Ali 4 python csv pandas

是否有某种方法只使用Pandas(最好是read_csv)从csv文件中读取具有特定索引的特定列?我知道read_csv提供了按列名读取特定列的功能,但数据文件没有标题,因此我不能使用列名.请注意,该文件太大,所以我不想读取整个文件然后子集.谢谢.

Rom*_*ain 5

这是一个说明EdChum给出的答案的例子.加载CSV文件还有很多其他选项,请查看API参考.

raw_data = {'first_name': ['Steve', 'Guido', 'John'],
        'last_name': ['Jobs', 'Van Rossum', "von Neumann"]}
df = pd.DataFrame(raw_data)
# Saving data without header
df.to_csv(path_or_buf='test.csv', header=False)
# Telling that there is no header and loading only the first name
df = pd.read_csv(filepath_or_buffer='test.csv', header=None, usecols=[1], names=['first_name'])
df

  first_name
0      Steve
1      Guido
2       John
Run Code Online (Sandbox Code Playgroud)