Home > Blockchain >  Pandas error "has no attribute sort_values" sorting a dataframe in Python
Pandas error "has no attribute sort_values" sorting a dataframe in Python

Time:03-02

I am using Panda version is 1.3.5 and I am running into an error when I am trying to use the sort_values function.

code

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)

The last line gives an error

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

When I print the dataframe, it looks like the following, so I should be able to use the post_id. I have checked the documentation and can't seem to find my issue.

dataframe

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]

CodePudding user response:

You're calling pandas.sort_values instead of calling sort_values on an instance of pandas.Dataframe. Your sorting line should likely be:
founded_edvideos_df = founded_edvideos_df.sort_values(by=['post_id'], ascending=True)

  • Related