pandas 比较引发TypeError:无法将dtyped [float64]数组与类型为[bool]的标量进行比较 [英] pandas comparison raises TypeError: cannot compare a dtyped [float64] array with a scalar of type [bool]
本文介绍了 pandas 比较引发TypeError:无法将dtyped [float64]数组与类型为[bool]的标量进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的dataFrame具有以下结构:
I have the following structure to my dataFrame:
Index: 1008 entries, Trial1.0 to Trial3.84
Data columns (total 5 columns):
CHUNK_NAME 1008 non-null values
LAMBDA 1008 non-null values
BETA 1008 non-null values
HIT_RATE 1008 non-null values
AVERAGE_RECIPROCAL_HITRATE 1008 non-null values
chunks=['300_321','322_343','344_365','366_387','388_408','366_408','344_408','322_408','300_408']
lam_beta=[(lambda1,beta1),(lambda1,beta2),(lambda1,beta3),...(lambda1,beta_n),(lambda2,beta1),(lambda2,beta2)...(lambda2,beta_n),........]
my_df.ix[my_df.CHUNK_NAME==chunks[0]&my_df.LAMBDA==lam_beta[0][0]]
我想获取特定块的数据帧的行,可以说chunks [0]和特定的lambda值.因此,在这种情况下,输出应为数据帧中具有CHUNK_NAME ='300_321'和LAMBDA = lambda1的所有行.每个返回的Beta值将有n行.但是相反,我遇到了以下错误.解决该问题的任何帮助将不胜感激.
I want to get the rows of the Dataframe for a particular chunk lets say chunks[0] and particular lambda value. So in this case the output should be all rows in the dataframe having CHUNK_NAME='300_321' and LAMBDA=lambda1. There would be n rows one for each beta value that would be returned. But instead I get the follwoing error. Any help in solving this problem would be appreciated.
TypeError: cannot compare a dtyped [float64] array with a scalar of type [bool]
推荐答案
&
的优先级高于==
.写:
my_df.ix[(my_df.CHUNK_NAME==chunks[0])&(my_df.LAMBDA==lam_beta[0][0])]
^ ^ ^ ^
这篇关于 pandas 比较引发TypeError:无法将dtyped [float64]数组与类型为[bool]的标量进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文