当其他两个列值相等时,如何获取特定的列值?
当其他2列值相等时,我想获得一个特定的列值,该如何完成?
用户 | 中心 | 右 |
---|---|---|
MARY | 1000 | 1000 |
JANE | 9999 | 2222 |
,假设我要获得的列值是“用户”。预期输出是
mary
I would like to get a specific column value when the other 2 columns values are equal, how can I accomplish this?
user | center | right |
---|---|---|
mary | 1000 | 1000 |
jane | 9999 | 2222 |
Let's say the column value that I want to get is 'user'. Expected output is
mary
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
另一个选项是使用
dataframe.query
,尽管它不是典型的用例。Another option is using
DataFrame.query
, although it's not quite its typical use case.或者
OR
我认为 @Naveed的答案非常有效。我建议解决问题的另一种方法是使用“ .loc”方法。
pandas.dataframe.loc
我会写代码像这样:
结果:
希望它有帮助!
I think @Naveed's answer works perfectly. Another way I would suggest solving the problem is with the '.loc' method.
pandas.DataFrame.loc
I would write the code like this:
Result:
Hope it helps!