-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

0

1 Answer 1

1

Use pandas.DataFrame.drop_duplicates:

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

For additional options check out the documentation for the method here

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.