I want to replace duplicates with NaN based on the following condition:
The ID & Code are duplicates. If the Code is different, keep it.
ID Code 1 A10 1 A10 1 A10 1 E39 1 I24 2 O32 2 K94 3 E39
I tried this:
df.loc[df['ID'].duplicated(), 'Code'] = np.nan
But it just keeps the first code and replaces any other code. I want something that only replaces the Code if the ID & Code matched with other instance.
ID Code 1 A10 1 NaN 1 NaN 1 E39 1 I24 2 O32 2 K94 3 E39