Suppose I have this df_atm
:
borough Longitude Latitude
0 bronx 40.79 -73.78
1 manhattan 40.78 -73.90
2 staten island 40.84 -73.95
3 NaN 40.57 -74.11
Every row represents an ATM withdrawal.
I hope to generate value for missing value based on the coordinate inside the Longitude and Latitude columns.
borough Longitude Latitude
0 bronx 40.79 -73.78
1 manhattan 40.78 -73.90
2 staten island 40.84 -73.95
3 staten island 40.57 -74.11
Since coordinate [40.57, -74.11] are inside Staten Island's borough.
I have generated a dict with boroughs' coordinates:
borough_dict = {"Bronx" : [40.837048, -73.865433], "Brooklyn" : [40.650002, -73.949997], "Manhattan" : [40.758896, -73.985130], "Queens" : [40.742054,-73.769417], "Staten Island" : [40.579021,-74.151535]}
And this is what I try so far (code/pseudocode):
df_atm['borough'] = df_atm.apply(
lambda row: **idk what do to here** if np.isnan(row['borough']) else row['borough'],
axis=1
)
Many thanks in advance!