python 调用 ggplot 包时报错 AttributeError: 'DataFrame' object has no attribute 'sort' 的解决方法

在学习数据可视化的时候,调用了python中的ggplot包时,提示一下报错信息。

报错信息
AttributeError:'DataFrame' object has no attribute 'sort'

查找资料发现,原来pandas在0.20.0以上的版本没有sort函数了,用的是sort_values和sort_index函数。

解决方法一

找到你ggplot包中的的stat_smooth.py模块,把sort改为sort_values。
在这里插入图片描述
找到

smoothed_data = smoothed_data.sort('x')

改为

smoothed_data = smoothed_data.sort_values('x')

在这里插入图片描述

解决方法二

找到ggplot包中的ggplot.py模块,把sort改为sort_values
在这里插入图片描述
找到

fill_levels = self.data[[fillcol_raw, fillcol]].sort(fillcol_raw)[fillcol].unique()

改为

fill_levels = self.data[[fillcol_raw, fillcol]].sort_values(fillcol_raw)[fillcol].unique()

在这里插入图片描述

解决方法三

直接把代码中的

sort()

改为

sort_values()
解决方法四

如果以上的方法都解決不了,那就把pandas换为0.20.0一下的版本就可以了,比如0.19.2版本(最接近0.20.0)。
在这里插入图片描述

另外,推荐在pycharm打开搜索修改,或者用notepad++等文本编辑器,因为可以直接搜索比较方面。

评论 22
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

苜苜的烂笔头

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值