文章目录
AttributeError: ‘Series’ object has no attribute ‘sort’
在对菜品盈利数据 进行帕累托分析时遇到以下问题:
原来是
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
AttributeError: ‘Series’ object has no attribute ‘reshape’
当代码运行到下面位置时:
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