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
usecols
的参数包含列名列表。如果需要多个列,则用逗号分隔它们,即['column_name1, 'column_name2', 'column_name3']
下面是一个例子,说明埃德楚姆给出的答案。有很多附加选项可以加载CSV文件,请检查API reference。
相关问题 更多 >
编程相关推荐