Ajit Wadalkar
Ajit Wadalkar

Reputation: 170

Pandas: remove duplicate multiple conditions based on column values

I have a big multi-index dataframe with lots of columns with lots of duplicate timestamps.

Now I want to drop duplicates but the problem is I want to keep the max value for column 1 and last value for other columns.

timestep        headers
        col1    col2    col3
1       2       5       6
1       1       3       4
2       3       5       6
2       4       7       8


Should give


timestep        headers
        col1    col2    col3
1       2       3       4
2       4       7       8

Upvotes: 0

Views: 79

Answers (1)

gosuto
gosuto

Reputation: 5741

If you .groupby() on the index you can take the .max() of each column:

df.groupby(df.index).max()
   col1  col2  col3
1     2     3     4
2     4     7     8

Upvotes: 1

Related Questions