nerd_gram
nerd_gram

Reputation: 53

Get specific column value of last row of a unique user in pandas

I have a table like this

user friend food
One Two apple
Three Four hello
Three Two. hey.

My desired output is this

user friend
One Two
Three Two.

Thanks.

Upvotes: 0

Views: 79

Answers (1)

user7864386
user7864386

Reputation:

You can use groupby_last:

out = df.groupby('user')['friend'].last().reset_index()

Output:

    user friend
0    One    Two
1  Three   Two.

Upvotes: 3

Related Questions