Python TypeError:无法执行';兰德';使用数据类型为[float64]的数组和类型为[float64]的标量

Python TypeError:无法执行';兰德';使用数据类型为[float64]的数组和类型为[float64]的标量,python,pandas,Python,Pandas,我有以下功能: 我正在调整函数,使异常值等于nan # Removing the outliers def removeOutliers(data, col): Q3 = np.quantile(data[col], 0.75) Q1 = np.quantile(data[col], 0.25) IQR = Q3 - Q1 print("IQR value for column %s is: %s" % (col, IQR))

我有以下功能: 我正在调整函数,使异常值等于nan

# Removing the outliers
def removeOutliers(data, col):
    Q3 = np.quantile(data[col], 0.75)
    Q1 = np.quantile(data[col], 0.25)
    IQR = Q3 - Q1
      
    print("IQR value for column %s is: %s" % (col, IQR))
    
    lower_range = Q1 - 5 * IQR
    upper_range = Q3 + 5 * IQR
    data.loc[data[col]<= lower_range & data[col]>= upper_range, col]=np.nan


removeOutliers(df, 'Minat')
你介意帮我吗


提前感谢

您从哪里得到的错误?确切地说是哪一行?@TimRoberts in data.loc[data[col]=上限,col]=np。您的问题在这里描述:<代码>&的优先级高于
=
,因此必须使用括号对比较进行分组。
TypeError: Cannot perform 'rand_' with a dtyped [float64] array and scalar of type [float64]