根据条件找到列值
我需要找到独特的名称,谁的年龄= 2,而使用python pandas = 9?
名称 | 年龄 | 频道 | CC |
---|---|---|---|
A | 2 | 9 | 3 |
B | 2 | 8 | 2 |
C | 3 | 9 | 1 |
A | 2 | 9 | 6 |
I need to find unique name, whose age=2 and and cond=9 using python pandas?
name | age | cond | cc |
---|---|---|---|
a | 2 | 9 | 3 |
b | 2 | 8 | 2 |
c | 3 | 9 | 1 |
a | 2 | 9 | 6 |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
pandas query> query 过滤数据框。然后在结果上使用unique()返回唯一名称。
有关更多查询示例,请参见在这里。
The Pandas query function allows for SQL-like queries to filter a data frame. Then use unique() on the results to return the unique name.
For more query examples, see here.
这将找到所有不同的行,其中年龄= 2,cond = 9
This will find all distinct rows where age = 2 and cond = 9
一种潜在的解决方案是将列放入
zip()
中,然后通过您的数据框架进行迭代:One potential solution is to put the columns in a
zip()
and then iterate through your dataframe like so: