提供了不可对齐的布尔系列键(类型为df [df [df])

时间:2017-05-09 15:03:43

标签: pandas dataframe

我有一个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]

并期望与上面的图像相同的输出??

1 个答案:

答案 0 :(得分:0)

您需要boolean indexingquery使用由|or),&and)或{{1}创建的布尔掩码(~):

not

或者:

df1 = df[(df['EmployeeName'] == 'JOSEPH DRISCOLL') & (df['BasePay'] > 140000)]

样品:

df1 = df.query("EmployeeName == 'JOSEPH DRISCOLL' & BasePay > 140000")