0

I have a dataframe with categorical value, numerical values and a counter. I want to keep only rows with the highest counter per category. So, if my dataframe is:

df = Tr. N1. N2. counter
     T1.  0.  3.    0 
     T1.  2.  3.    0
     T1.  7.  1.    1 
     T2.  2.  7.    0
     T2.  0.  9.    1 
     T2.  5.  6.    2
     T2.  3.  2.    2 
     T3.  7.  8.    0

For each value of Tr, I want to keep only rows with the highest counter. So, the new df will be:

df = Tr. N1. N2. counter

     T1.  7.  1.    1  
     T2.  5.  6.    2
     T2.  3.  2.    2 
     T3.  7.  8.    0

What is the best way to do so?

Cranjis
  • 1,590
  • 8
  • 31
  • 64

0 Answers0