Q:

How to remove duplicates based on two columns removing the the largest of 3rd column in pandas dataframe?

Suppose I have a pandas dataframe that is like this:
df=
A  B  6  2
A  C  4  2
D  F  9  3
K  L  8  9
A  B  4  3
D  F  8  2

How can I say, if columns A and B have duplicates remove the ones that have the largest column C?
So for instance we can see lines 1 and 5 have the same columns A and B.
A  B  6  2 (Line 1)
A  B  4  3 (Line 5)

I want to remove line 1 as 6 is greater than 4.
So my output should be
A  C  4  2
K  L  8  9
A  B  4  3
D  F  8  2

A:

Try sorting the column in descending order on which you need to find max value using
pd.sort_values
Then drop_duplicates using pd.drop_duplicate
df.sort_values(by=['C'],ascending=[True],inplace=True)
df.drop_duplicates(subset=['A','B'],inplace=True)

