在 Python 中对数据帧进行排序时"has no attribute sort_values" Pandas 错误



我使用的Panda版本是1.3.5,在尝试使用sort_values函数时遇到错误。

代码

founded_edvideos_list = find_matching_posts_forupdate(video_id_list, stop_at_page=stop_at_page)
founded_edvideos_df = pd.DataFrame(founded_edvideos_list)
founded_edvideos_df = pd.sort_values(by=['post_id'], ascending=True)

最后一行给出错误

getattr__ raise AttributeError(f"module 'pandas' has no attribute '{name}'") AttributeError: module 'pandas' has no attribute 'sort_values'

当我打印数据帧时,它看起来如下,所以我应该能够使用post_id。我已经查看了文档,似乎找不到我的问题。

数据帧

post_id                                         title  ...      vid_type vid_record
0    12994              Trailblazer Melba Pattillo Beals  ...  [6923, 6926]     [6929]
1    12992                         Trailblazer Asha Prem  ...        [6923]     [6929]
2    12894  Trailblazers Melisa Mujanovic and Nina Nukic  ...  [6923, 6926]     [6929]

pandas.Dataframe的实例上调用pandas.sort_values而不是sort_values。您的分拣线应该是:
founded_edvideos_df = founded_edvideos_df.sort_values(by=['post_id'], ascending=True)

相关内容

最新更新