匹配数据框中的两个列
我在DataFrame DF中有两个列,
ID Name
AXD2 SAM S
AXD2 SAM
SCA4 JIM
SCA4 JIM JONES
ASCQ JOHN
我需要输出才能获得唯一的ID,并且应该仅匹配名字,
ID Name
AXD2 SAM S
SCA4 JIM
ASCQ JOHN
任何建议吗?
I have two columns in dataframe df
ID Name
AXD2 SAM S
AXD2 SAM
SCA4 JIM
SCA4 JIM JONES
ASCQ JOHN
I need the output to get a unique id and should match the first name only,
ID Name
AXD2 SAM S
SCA4 JIM
ASCQ JOHN
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
groupby
与agg
,并获得的第一个
nameYou can use
groupby
withagg
and getfirst
ofName
使用
drop_duplicates
:Use
drop_duplicates
:您可以使用cumcount()查找ID的第一个迭代名称
You can use cumcount() to find the first iteration name of the ID