我有一个df和条件df [df ['EmployeeName'] =='JOSEPH DRISCOLL']给出以下输出enter image description here
当我输入这个df [df ['EmployeeName'] =='JOSEPH DRISCOLL'] ['BasePay']> 140000个
它提供了这样的输出
24 True
名称:BasePay,dtype:bool
现在我不能做这样的事情
df [df [df ['EmployeeName'] =='JOSEPH DRISCOLL'] ['BasePay']> 140000]
并期望与上面的图像相同的输出??
答案 0 :(得分:0)
您需要boolean indexing
或query
使用由|
(or
),&
(and
)或{{1}创建的布尔掩码(~
):
not
或者:
df1 = df[(df['EmployeeName'] == 'JOSEPH DRISCOLL') & (df['BasePay'] > 140000)]
样品:
df1 = df.query("EmployeeName == 'JOSEPH DRISCOLL' & BasePay > 140000")