Streamlit - TypeError: sort_index() got an unexpected keyword argument 'ignore_index'

Streamlit - TypeError: sort_index() got an unexpected keyword argument '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)#

In the official pandas documentation, 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)

从文档中,我找到了 ignore_index 1.0.0 版的新增内容。

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

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

对我来说,codechef.com,

import pandas as pd
print(pd.__version__)

显示 0.23.4 之前的版本 1.0.0,其中 ignore_index 首次出现在 pandas.DataFrame.sort_values