我正在尝试定义一个函数来计算numpy中的IQR。代码真的很简单,但我一直收到一个错误消息,我搞不懂
def calculate_icq(variable):
icq = 0
icq += (np.percentile(df.variable, 75) - np.percentile(df.variable, 25))
return icq当我使用一个列变量(比如calculate_icq('Price'))运行函数时,它显示'DataFrame‘对象没有'variable’属性。
术语“价格”不应该映射到变量并替换它吗?
发布于 2019-09-28 08:39:42
你不能这样调用列。您需要使用df[variable]。
def calculate_icq(variable):
icq = 0
icq += (np.percentile(df[variable], 75) - np.percentile(df[variable], 25))
return icqhttps://stackoverflow.com/questions/58142399
复制相似问题