持续记录《python数据分析与挖掘实战》代码跑不起来 解决方法
3.2.5 贡献度分析
在对菜品盈利数据 进行帕累托分析时遇到以下问题:
原来是
data.sort(ascending = False)
结果报错
AttributeError: ‘Series’ object has no attribute ‘sort’
后来经查阅
Series.sort_index(ascending=True) 根据索引返回已排序的新对象
换成下面这样就可以了
data.sort_index(ascending = False)
4.3.3 连续属性离散化
第一处:
kmodel.fit(data.reshape((len(data), 1))) # 训练模型
报错信息
‘Series’ object has no attribute ‘reshape’
修改:
kmodel.fit(data.values.reshape((len(data), 1))) # 训练模型
第二处:
原本代码:
w = pd.rolling_mean(c, 2).iloc[1:] # 相邻两项求中点,作为边界点
报错:
module ‘pandas’ has no attribute ‘rolling_mean’
解决:
w = c.rolling(2).mean().iloc[1:]