0

I have df with names Mark,Luke,Leno with two columns a and b. I want the most recent updated row for each names.

df

                        a       b

                    0   Mark    120
                    1   Luke    25
                    2   Leno    65
                    3   Mark    21
                    4   Mark    100
                    5   Luke    57
                    6   Luke    54
                    7   Mark    7
                    8   Leno    98
                    9   Leno    79
                    10  Mark   100

Resultant Output:

                        a       b

                    10   Mark    100
                     6   Luke    54
                     9   Leno    79
  • Found the sountion, Any other ways `df = df.drop_duplicates('a', keep='last')` –  Mar 27 '20 at 11:17

1 Answers1

0

You can do a drop_duplicates keeping the last appearance.

df_last_appearance = df.drop_duplicates(subset=["a"], keep="last")
sergiomahi
  • 964
  • 2
  • 8
  • 21