I have a pandas dataframe with two columns : locationid, geo_loc. locationid column has missing values.
I want to get the geo_loc value of the missing locationid row, then search this geo_loc value in geo_loc column and get the loction id.
df1 = pd.DataFrame({'locationid':[111, np.nan, 145, np.nan, 189,np.nan, 158, 145],
'geo_loc':['G12','K11','B16','G12','B22','B16', 'K11',he l 'B16']})
df
I need the final output like this:
index 1 of locationid is missing and the corresponding geo_loc value is 'K11'. I would look this 'K11' in geo_loc column and index 6 has locationid 158. With this value I want to fill the missing value in index 1.
I tried these codes and they didnt work.
df1['locationid'] = df1.locationid.fillna(df1.groupby('geo_loc')['locationid'].max())
df1['locationid'] = df1.locationid.fillna(df1.groupby('geo_loc').apply(lambda x: print(list(x.locationid)[0])))

