在对菜品盈利数据 进行帕累托分析时遇到以下问题: 原来是
data.sort(ascending = False)
结果报错
AttributeError: ‘Series’ object has no attribute ‘sort’
后来经查阅
Series.sort_index(ascending=True) 根据索引返回已排序的新对象
换成下面这样就可以了
data.sort_index(ascending = False)
参考:https://blog.csdn.net/welcome_yu/article/details/102492386
当代码运行到下面位置时:
from sklearn.cluster import KMeans # 引入KMeans
kmodel = KMeans(n_clusters=k, n_jobs=4) # 建立模型,n_jobs是并行数,一般等于CPU数较好
kmodel.fit(data.reshape((len(data), 1))) # 训练模型
报错:AttributeError: ‘Series’ object has no attribute ‘reshape’
出错的原因是Series没有reshape这个接口,而Series有values这个接口,
解决的办法是调用values接口,然后调用values中的reshape方法。
如下:
kmodel.fit(data.values.reshape((len(data), 1))) # 训练模型
参考:https://blog.csdn.net/weixin_38664232/article/details/86760297
解决办法:将“sort”改为“sort_values”。
如:
c_df_sort=c_df.sort(columns=0,ascending=False)
改为:
c_df_sort=c_df.sort_values(0,ascending=False)
参考:https://blog.csdn.net/qq_34197944/article/details/102879943
moving_avg = pd.rolling_mean(ts_log,12)
上面代码报错:AttributeError: module ‘pandas’ has no attribute ‘rolling_mean’
解决方法:
moving_avg = ts_log.rolling(12).mean()
参考:https://stackoom.com/question/3Pou4/%E6%A8%A1%E5%9D%97-pandas-%E6%B2%A1%E6%9C%89%E5%B1%9E%E6%80%A7-rolling-mean
错误:
ImportError: [joblib] Attempting to do parallel computing without protecting your import on a system that does not support forking. To use parallel-computing in a script, you must protect your main loop using “if __name__ == '__main__'”. Please see the joblib documentation on Parallel for more information
解决方案:
if __name__=='__main__'://加入此行代码即可
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有