-2

Is it possible to get last entry for every unique item in dataframe? I have a this kind dataframe:

User | Product | Date 
u1   | p1      | d1
u1   | p2      | d2
u2   | p1      | d1
u2   | p3      | d2
u3   | p5      | d1

So I want to get last records of users, for example dataframe It must return,

user | product
u1   | p2
u2   | p3
u3   | p5

is it possible to get last record by date.

Thanks

mklement0
  • 382,024
  • 64
  • 607
  • 775
yigitozmen
  • 947
  • 4
  • 23
  • 42

1 Answers1

1

Use pandas.DataFrame.drop_duplicates:

df.drop_duplicates('User', keep='last')

For additional options check out the documentation for the method here

C. Feenstra
  • 593
  • 3
  • 11