问题描述
我正在尝试使用以下代码在Python中对多个索引进行排序,这给了我代码下面提供的错误:
raw_data.sort_index(level='employee_id',ascending=False,inplace=True).sort_index(level='PAYCODE_ID',ascending=True,inplace=True)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-732-d2ad9fdef0b4> in <module>
----> 1 raw_data.sort_index(level='employee_id',inplace=True)
AttributeError: 'NoneType' object has no attribute 'sort_index'
我认为在第一个“ sort_index”方法之后,python会导致“ None”对象类型。根据python文档,如果将'inplace'参数设置为True,则返回对象将是一个数据框。
还要注意,当我将方法拆分为以下两行代码时,它将已排序的结果存储到raw_data数据帧中:
raw_data.sort_index(level='employee_id',inplace=True)
raw_data.sort_index(level='PAYCODE_ID',inplace=True)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)