我確定我做的事情相當愚蠢,但我只是沒有看到它!python字典關鍵錯誤excel
這裏是我試圖運行代碼:
import pandas as pd
geo_dic = pd.read_excel('cityzip.xlsx', index_col=0).to_dict()
print geo_dic[' Longitude']['601'][0]
cityzip.xlsx包含這些行(還有更多):
Postal Latitude Longitude
601 18.1786 -66.7518
我收到 「KeyError異常: '601'」 每時間。
最後,我想使用geopy來計算並將一組城市座標中的zip代碼距離寫入xlsx文件,因此,下一步的任何提示或資源都將得到讚賞!
如果沒有更多關於'geo_dic'的外觀信息,很難分辨出來。你可以添加什麼'geo_dic.head()'返回? – mgilbert
'print geo_dic.head() AttributeError:'dict'對象沒有屬性'head'' – taylorhamcheese
對不起,我誤讀了,我的意思是在轉換爲字典之前運行該數據框 – mgilbert