iT邦幫忙

0

python的csv檔案內特定項目匯入遇到大難題

2021-05-16 15:35:25519 瀏覽

import csv
with open('108年產業及社福外籍勞工人數_縣市.csv',newline = '') as csvfile:
csvreader = csv.DictReader(csvfile)
for old in csvreader:
print(old['產業及社福外籍勞工人數'])

其顯示錯誤:
Traceback (most recent call last):
File "c:\Users\Eric Chang\Eric\python\108labor.py", line 5, in
print(old['產業及社福外籍勞工人數'])
KeyError: '產業及社福外籍勞工人數'

powerc iT邦新手 4 級 ‧ 2021-05-17 11:25:03 檢舉
猜測編碼問題

1 個回答

0
I code so I am
iT邦高手 1 級 ‧ 2021-05-17 23:30:37
import pandas as pd
df = pd.read_csv('108年產業及社福外籍勞工人數_縣市.csv')
print(df)

我要發表回答

立即登入回答