读取 CSV 文件
带标题的数据,以分号而不是逗号分隔
file:table.csv
index;name;occupation
1;Alice;Saleswoman
2;Bob;Engineer
3;Charlie;Janitor
码:
import pandas as pd
pd.read_csv('table.csv', sep=';', index_col=0)
输出 :
name occupation
index
1 Alice Salesman
2 Bob Engineer
3 Charlie Janitor
没有行名称或索引和逗号作为分隔符的表
file:table.csv
Alice,Saleswoman
Bob,Engineer
Charlie,Janitor
码:
import pandas as pd
pd.read_csv('table.csv', names=['name','occupation'])
输出:
name occupation
0 Alice Salesman
1 Bob Engineer
2 Charlie Janitor
可以在 read_csv
文档页面中找到进一步的说明