首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >熊猫错误“没有属性sort_values”在Python中对数据进行排序

熊猫错误“没有属性sort_values”在Python中对数据进行排序
EN

Stack Overflow用户
提问于 2022-03-01 18:33:47
回答 1查看 439关注 0票数 0

我使用的熊猫版本是1.3.5,当我试图使用sort_values函数时,我遇到了一个错误。

代码语言:javascript
复制
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'

当我打印dataframe时,它看起来如下所示,所以我应该能够使用post_id。我检查了文件,似乎找不到我的问题。

dataframe

代码语言:javascript
复制
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]
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-01 18:37:13

您正在调用pandas.sort_values,而不是调用pandas.Dataframe实例上的sort_values。您的排序线应该是:

founded_edvideos_df = founded_edvideos_df.sort_values(by=['post_id'], ascending=True)

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71313111

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档