前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >[934]AttributeError: ‘Series‘ object has no attribute ‘sort‘

[934]AttributeError: ‘Series‘ object has no attribute ‘sort‘

作者头像
周小董
发布于 2021-01-29 02:23:13
发布于 2021-01-29 02:23:13
1.7K00
代码可运行
举报
文章被收录于专栏:python前行者python前行者
运行总次数:0
代码可运行

文章目录

AttributeError: ‘Series’ object has no attribute ‘sort’

在对菜品盈利数据 进行帕累托分析时遇到以下问题: 原来是

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
data.sort(ascending = False)

结果报错

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
AttributeError: ‘Series’ object has no attribute ‘sort’

后来经查阅

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Series.sort_index(ascending=True) 根据索引返回已排序的新对象

换成下面这样就可以了

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
data.sort_index(ascending = False)

参考:https://blog.csdn.net/welcome_yu/article/details/102492386

AttributeError: ‘Series’ object has no attribute ‘reshape’

当代码运行到下面位置时:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
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方法。

如下:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
kmodel.fit(data.values.reshape((len(data), 1)))  # 训练模型

参考:https://blog.csdn.net/weixin_38664232/article/details/86760297

AttributeError:‘DataFrame’ object has no attribute ‘sort’

解决办法:将“sort”改为“sort_values”。

如:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
c_df_sort=c_df.sort(columns=0,ascending=False)

改为:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
c_df_sort=c_df.sort_values(0,ascending=False)

参考:https://blog.csdn.net/qq_34197944/article/details/102879943

AttributeError: module ‘pandas’ has no attribute ‘rolling_mean’

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
moving_avg = pd.rolling_mean(ts_log,12)

上面代码报错:AttributeError: module ‘pandas’ has no attribute ‘rolling_mean’

解决方法:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
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

python报错ImportError: [joblib] Attempting to do parallel computing without protecting

错误:

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

解决方案:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
if __name__=='__main__'://加入此行代码即可
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021/01/04 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 文章目录
  • AttributeError: ‘Series’ object has no attribute ‘sort’
  • AttributeError: ‘Series’ object has no attribute ‘reshape’
  • AttributeError:‘DataFrame’ object has no attribute ‘sort’
  • AttributeError: module ‘pandas’ has no attribute ‘rolling_mean’
  • python报错ImportError: [joblib] Attempting to do parallel computing without protecting
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档