[英]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我想要的 output 是这个
user![]() |
friend![]() |
---|---|
One![]() |
Two![]() |
Three![]() |
Two.![]() |
Thanks.谢谢。
You can use groupby_last
:您可以使用
groupby_last
:
out = df.groupby('user')['friend'].last().reset_index()
Output: Output:
user friend
0 One Two
1 Three Two.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.