我试图在数据帧“combined_sf2”中应用.mean函数,其中包含形状“43722行×62列”
我想从我的数据帧中为每一行计算一系列不同属性中某些值的平均值。然后生成名为“wkQtyEXTMean”的新属性/列,该属性/列将包含每行所选属性值范围的平均值
我尝试使用统计方法中的.mean函数创建以下函数:
#function create to take the range of the selected attributes, if the sum is zero, so return the message 'thre is no mean', if not, calculate the mean
import statistics
def wkQtyEXTMean(row):
if (row['wk13QtyEXT']+row['wk12QtyEXT']) == 0:
return 'No mean'
else:
return statistics.mean(row['wk13QtyEXT']+row['wk12QtyEXT'])
#generating new column
combined_sf2['wkQtyEXTMean'] = combined_sf2.apply(wkQtyEXTMean, axis=1)
但我得到了以下错误:
("'int' object is not iterable", 'occurred at index 43721')
有什么建议我该怎么办
请找到最新的答案
13.25万美元
16.25万 2 23.333
3.2.666667
450万
数据类型:64
这就是答案。 10.1
老对话:
这是mean的语法
现在你做错的是
尝试(你的方法):
或者没有
statistics.mean
:或者没有
apply
:或者如果您已经在使用NumPy(
np
):相关问题 更多 >
编程相关推荐