I have the following table:\
Name | ID | Azimut\
foo | 1 | 180\
foo | 6 | NaN\
bar | 1 | NaN\
bar | 6 | 200
I want to search for duplicates that have IDs with the value of 1 or 6 (the table can have other numbers) and if the "Azimut" value is NaN, complete it with the value of its corresponding duplicate, returning the following:
Name | ID | Azimut\
foo | 1 | 180\
foo | 6 | 180\
bar | 1 | 200\
bar | 6 | 200
What I've tried so far:
nan_rows = df.loc[(df['ID'] == 6) & (df['Azimut'].isna())]
values = df.loc[(df['Name'].isin(nan_rows['Name'])) & (df['ID'] == 1), 'Azimut']
df.loc[(df['ID'] == 6) & (df['Azimut'].isna(), 'Azimut'] = values.values
I would have to do similar code for the reverse case (ID = 1 is NaN and complete with ID = 6), and it wouldn't work if there is no pair of IDs 1 and 6 (It doesn't verify the duplicates). I hope the question is well redacted and I'm listening for any way I could improve it.