[英]Find the column value based on condition
I need to find unique name, whose age=2 and and cond=9 using python pandas?我需要使用 python pandas 找到唯一的名称,其年龄 = 2 和 cond = 9?
name姓名 | age年龄 | cond条件 | cc抄送 |
---|---|---|---|
a一个 | 2 2 | 9 9 | 3 3 |
b b | 2 2 | 8 8 | 2 2 |
c C | 3 3 | 9 9 | 1 1 |
a一个 | 2 2 | 9 9 | 6 6 |
这将找到 age = 2 和 cond = 9 的所有不同行
df.loc[(df['age'] == 2) & (df['cond'] == 9)][['name', 'cc']].drop_duplicates()
enter code here one potential solution is to put the columns in a zip() and then iterate through you dataframe like so在此处输入代码一种可能的解决方案是将列放在 zip() 中,然后像这样遍历您的数据框
for name, age, cond in zip(df['name'], df['Age'], df['cond']):
if(age == 2 and cond ==9):
print(name)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.