简体   繁体   English

获取 pandas 中唯一用户的最后一行的特定列值

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM