讀取 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
文件頁面中找到進一步的說明