I’m working with data from an excel file like this.
JavaScript
x
7
1
A B
2
2001-05-01 12:30 10
3
2001-05-01 12:30 20
4
2001-05-05 11:50 30
5
2001-05-05 11:50 40
6
2002-03-22 14:12 10
7
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
1
2
1
df_clean=df_raw.sort_values('A', ascending=False).drop_duplicates('B', ignore_index=True)
2
and not sort_index()