Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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]

>Solution :

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)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading