Ellenőrizze a dataframe oszlopban látható a bool ha igaz / hamis, ha hamis, geokódolni csak azokat az értékeket

szavazat
0

Én használ a [Geocoder python API könyvtárat] [1]. Van egy panda dataframe oszlopon logikai igaz / hamis alapján, ha már van, hogy az adott címre geokódoltnak vagy sem. Van egy módja annak, hogy módosítsa a meglévő kódot geokódolása alapján, ha én azt geokódoltnak, vagy nem?

Most minden ez is nyomtatni igaz állítás, majd geokódoktól mindent, függetlenül a logikai én. Segítsen kérem!

Itt van egy másik módja annak, hogy tegye:

Van egy dataframe Tweets. Ha egy tweet geokódoltnak, már jelzett, hogy tweetet a True (ha már geokódoltnak) vagy hamis (Ha nem lett geokódoltnak). Amit megpróbálok tennie, hogy ellenőrizze, ha az oszlop Igaz, nyomtassa ki azt a sort. Else if hogy sor hamis, akkor küldje el az én for ciklus geokódolása. Fogom szerkeszteni az eredeti post egy bemenet.

Itt van az én exisiting kód:

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 

Íme egy példa a JSON fájl input:

{
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
        }
    }
 ]

}

A kérdést 12/06/2018 19:31
a forrás felhasználó
Más nyelveken...                            


1 válasz

szavazat
0

A legegyszerűbb módja az, hogy sétálni az adathalmaz és ha nincs coordskulcs, add meg:

for data in your_data_set['data']:
    data['coords'] = data.setdefault('coords',  geocoder.osm(data'location_x']).latlang)

Ezután alakítani egy dataframe.

Ha már van, mint egy dataframe:

df.loc[df['coords'] == False, 'coords'] = geocoder.osm(df['location_x']).latlang
Válaszolt 12/06/2018 20:10
a forrás felhasználó

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more