AttributeError: 'Series' object has no attribute 'sortlevel'
程序员文章站
2022-04-14 09:31:09
...
1、原因
pandas的包中在0.23.4版本中就取消了sort方法,老版本的Series和DataFrame对象中还包含这个函数,新版本中推荐使用sort_index和sort_values函数
2、解决方法
import pandas as pd
import numpy as np
ser_obj =pd.Series(np.random.randn(12),
index=[['a','a','a','b','b','b','c','c','c','d','d','d'],
[0,1,2,0,1,2,0,1,2,0,1,2]])
print(ser_obj)
print( ser_obj.sort_values() )
①构造Series
②sort_values()
③sort_index()
推荐阅读
-
AttributeError: module ‘community‘ has no attribute ‘best_partition‘ 问题解决方法
-
【python】解决AttributeError: module ‘scipy.misc‘ has no attribute ‘toimage‘问题
-
【Tensorflow】Linux下Tensorflow报错:AttributeError: module ‘tensorflow‘ has no attribute ‘xxxx‘
-
AttributeError: 'module' object has no attribute 'main'
-
AttributeError: module 'sklearn' has no attribute 'linear_model'
-
解决Keras报错AttributeError: 'NoneType' object has no attribute 'inbound_nodes'
-
解决'DataFrame' object has no attribute 'sort'
-
‘MyObject‘ object has no attribute ‘***‘
-
AttributeError: ‘NoneType‘ object has no attribute ‘origin‘解决办法
-
AttributeError: ‘set‘ object has no attribute ‘append‘解决办法