熊猫比较会引起TypeError:无法比较一个dtyped [float64]数组和一个标量类型[bool]

时间:2021-12-31 17:03:19

I have the following structure to my dataFrame:

我的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]]

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.

我想要得到一个特定区块的Dataframe的行,让我们说块[0]和特定的lambda值。因此,在这种情况下,输出应该是dataframe中的所有行,其中包含CHUNK_NAME='300_321'和LAMBDA=lambda1。每个返回的beta值都有n行。相反,我得到了下面的错误。如果能帮助解决这个问题,我们将不胜感激。

TypeError: cannot compare a dtyped [float64] array with a scalar of type [bool]

1 个解决方案

#1


45  

& has higher precedence than ==. Write:

优先级高于==。写:

my_df.ix[(my_df.CHUNK_NAME==chunks[0])&(my_df.LAMBDA==lam_beta[0][0])]
         ^                           ^ ^                            ^

#1


45  

& has higher precedence than ==. Write:

优先级高于==。写:

my_df.ix[(my_df.CHUNK_NAME==chunks[0])&(my_df.LAMBDA==lam_beta[0][0])]
         ^                           ^ ^                            ^