Ben [geocoder piton API kitaplığı] kullanıyorum [1]. Zaten belirli bir adresi coğrafi kodlaması veya değil varsa dayanan Doğru / Yanlış boolean bir pandalar dataframe sütun var. Bunun coğrafi kodlaması veya değil eğer dayalı coğrafi kodlaması Mevcut kodunu değiştirmek için bir yol var mı?
Şu anda öyle hepsi gerçek deyimi yazdırmak ve daha sonra ne olursa olsun ben boolean, herşeyi geocodes. Yardım lütfen!
İşte koymak için başka bir yoludur:
Ben Tweets bir dataframe var. Bir Tweet coğrafi kodlaması olsaydı, ben işaretlediğiniz (o coğrafi kodlaması edilmişse) bir gerçek ile Tweetle veya Yanlış ki (o coğrafi kodlaması değilse). Ne yapmaya çalışıyorum sütun Doğru ise, bu satırın çıktısını kontrol etmektir. o satır False Else, sonra döngü kodlaması yapılacak benim içine göndermek. Bir giriş için orijinal yayını düzenleyeceksiniz.
İşte benim Mevcut bir koddur:
for d in tweets2['Exist']:
if d is True:
print d
elif d.any() is False:
coord = []
for index, row in tweets2.iterrows():
print(row['location_x'])
time.sleep(1.01)
g = geocoder.osm(row['location_x'])
geo = g.latlng
print(geo)
coord.append(geo)
else:
pass
İşte bir girdi olarak JSON dosyası örneğidir:
{
data: [
{
user_id: 3299796214,
features: {
screen_name: SaveOurSparrows,
text: Details confirmed for inquiry into #INEOS #Derbyshire #Fracking site! \n\nAnti Fracking, #keepitintheground #wesaidno\u2026,
location: West Pennine Moors AONB SSSI,
tweets: 3,
geo_type: User location,
primary_geo: West Pennine Moors AONB SSSI,
id: 3299796214,
name: SaveOurSparrows,
Exist: True
}
},
{
user_id: 3302831409,
features: {
screen_name: ProjectLower,
text: Cutting down on energy costs is the dream for many #smallbusinesses, but to put ideas into practice isn\u2019t always ea\u2026,
location: Manchester,
tweets: 1,
geo_type: User location,
primary_geo: Manchester,
id: 3302831409,
name: Project Lower,
Exist: False
}
},
{
user_id: 2205129714,
features: {
screen_name: AmbCanHaiti,
text: Petit-d\u00e9jeuner causerie le mercredi 28 mars 2018 \u00e0 l'h\u00f4tel Montana sur l'\u00e9nergie #micror\u00e9seaux #microgrids\u2026,
location: Haiti,
tweets: 1,
geo_type: User location,
primary_geo: Haiti,
id: 2205129714,
name: Canada en Ha\u00efti,
Exist: False
}
}
]
}













