首页 > 解决方案 > Streamlit - TypeError:sort_index()得到了一个意外的关键字参数'ignore_index'

问题描述

我正在尝试使用以下行对索引进行排序。

task_count_20.sort_index(ascending=False, ignore_index=True, inplace=True)

上面的代码行在Google colab本地环境中工作,但是当我尝试使用 构建应用程序时streamlit,我收到以下回溯错误。

TypeError: sort_index() got an unexpected keyword argument 'ignore_index'
Traceback:
File "app.py", line 601, in <module>
    Lollipop_count_plot(df, col, count=20)
File "app.py", line 209, in Lollipop_count_plot
    task_count_20.sort_index(ascending=False, ignore_index=True, inplace=True)#

在 pandas 官方文档中,sort_index()有关键字ignore_index

pandas.DataFrame.sort_index

DataFrame.sort_index(axis=0, level=None, ascending=True, inplace=False, kind='quicksort', na_position='last', sort_remaining=True, ignore_index=False, key=None)

标签: pythonpandasstreamlit

解决方案


从文档中,我找到了ignore_index1.0.0 版的新功能。

https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.sort_index.html

在此处输入图像描述

也许您需要检查pandas库版本。


推荐阅读