Skip to content
Advertisement

how to eliminate duplicate rows in column A keeping the maximum value in B in python

I’m working with data from an excel file like this.

JavaScript

I’m using this line of code to eliminate the duplicates keeping the maximum

df_clean=df_raw.sort_values('A', ascending=False).drop_duplicates('B').sort_index()

but I’m obtaining this error

Index(['B'], dtype='object')

I don’t know which could be the problem since I’m doing it after the upload of the file.

Advertisement

Answer

If I can assume that your index is just a RangeIndex then I think what you are looking for is:

JavaScript

and not sort_index()

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement