I have a dataset where I want to remove duplicates based on some conditions.
For example, say I have a table as
ID date group
3001 2010 DCM
3001 2012 NII
3001 2012 DCM
I wanna say look into ID column for the similar IDs, if two dates were similar keep the row that group is NII
so it would become
ID date group
3001 2010 DCM
3001 2012 NII
Leverage duplicated
here:
df[~df.duplicated(['ID', 'date'], keep=False) | df['group'].eq('NII')]
ID date group
0 3001 2010 DCM
1 3001 2012 NII
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With