第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Geopy 沒有所有相同的地址鍵

Geopy 沒有所有相同的地址鍵

白板的微信 2021-09-11 13:19:18
如何檢測location.raw["address"]字典中缺少的鍵。這是因為,某些地址沒有['city'] or ['road']密鑰 :(我很難將數(shù)據(jù)保存在 Python 數(shù)據(jù)幀中。這是我的代碼:from geopy.geocoders import Nominatimr=[]h=[] #empty listc=[]for i in df['coordinates']:    loc=geolocator.reverse("%s"%i,timeout=120)    print(loc)    if loc.raw["address"]["road"] == None: #i tried use this way, not works        r.append(" ")        print("masuk 1")    else:         road=loc.raw["address"]["road"]        r.append(road)        print("masuk 2")    ham=loc.raw["address"]    name=loc.raw["display_name"]    h.append(ham)    c.append(name)df = pd.DataFrame({'text':text,'city':c,'neighbourhood':h})
查看完整描述

1 回答

?
喵喔喔

TA貢獻1735條經(jīng)驗 獲得超5個贊

您可以使用in關(guān)鍵字來檢查密鑰是否出現(xiàn)在dict:


a = {1:2, 'x': [3,4]}

print(1 in a) # True

print(2 in a) # False

print('x' in a) # True

此外,dict對象有g(shù)et方法,如果鍵不存在,它會返回一些值:


a.get(1) # 2

a.get(2) # None -- default value

a.get(2, 'n/a') # 'n/a'


查看完整回答
反對 回復(fù) 2021-09-11
  • 1 回答
  • 0 關(guān)注
  • 174 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號