1. 程式人生 > 其它 >python報錯解決方法:Must have equal len keys and value when setting with an iterable

python報錯解決方法:Must have equal len keys and value when setting with an iterable

技術標籤:pythonpython

報錯型別

在編寫爬蟲程式時,出現以下提示:

Must have equal len keys and value when setting with an iterable

讀取的資料型別如下:

報錯程式碼:

df.loc[m,'geo']=s['geo']

原因

將內容存入dataframe時出現的情況,原因是所爬取的物件是一個列表,左右兩邊鍵值不相等而出現報錯提示!

修改

if s['geo']!=None:
    df.loc[m,'geo']=str(s['geo']['coordinates'][1])+','+str(s['geo']['coordinates'][0])
else:
    df.loc[m,'geo']=''

修改後成功解決問題