相关疑难解决方法(0)

Pandas中布尔索引的逻辑运算符

我在Pandas中使用布尔索引.问题是为什么声明:

a[(a['some_column']==some_number) & (a['some_other_column']==some_other_number)]
Run Code Online (Sandbox Code Playgroud)

工作正常,而

a[(a['some_column']==some_number) and (a['some_other_column']==some_other_number)]
Run Code Online (Sandbox Code Playgroud)

存在错误?

例:

a=pd.DataFrame({'x':[1,1],'y':[10,20]})

In: a[(a['x']==1)&(a['y']==10)]
Out:    x   y
     0  1  10

In: a[(a['x']==1) and (a['y']==10)]
Out: ValueError: The truth value of an array with more than one element is ambiguous.     Use a.any() or a.all()
Run Code Online (Sandbox Code Playgroud)

python filtering boolean dataframe pandas

119
推荐指数
3
解决办法
14万
查看次数

标签 统计

boolean ×1

dataframe ×1

filtering ×1

pandas ×1

python ×1