I have this df, and want to drop duplicates based on the max value counts of 'rating' (its binary field). None of the drop_duplicates with combination of grouby, max, count isn't fecthing the desired output. Any suggestion highly appreciated.
df = pd.DataFrame({
'brand': ['Yum Yum', 'Yum Yum', 'Yum Yum', 'Indomie', 'Indomie', 'Indomie', 'Cup','Pack'],
'rating': [1, 1, 0, 1, 0, 0, 1, 0]})
Desired Output :
brand | rating |
---|---|
Yum Yum | 1 |
Indomie | 0 |
Cup | 1 |
Pack | 0 |
tried below but not helping with desired output.
df.groupby(["brand",'rating']).max().reset_index()
df.drop_duplicates(subset=['brand'], keep='last')