I'm trying to sort a datafarame using the pandas sort_values() function but the returned result is sorted in a strange way as shown in the image attached 
2 Answers
Problem is column Citation is strings repr of numbers, so need convert to numeric by Series.astype:
au_df['Citation'] = au_df['Citation'].astype(int)
au_df_srtd = au_df.sort_values('Citations')
If not working because at least one string value in numbers use to_numeric with errors='coerce' for convert non numbers to NaNs:
au_df['Citation'] = pd.to_numeric(au_df['Citation'], errors='coerce')
au_df_srtd = au_df.sort_values('Citations')
2 Comments
U13-Forward
You're faster 7 sec
U13-Forward
nice one with
to_numeric tho.Because they must be strings, so try using astype:
au_df['Citations'] = au_df['Citations'].astype(int)
au_df_srtd = au_df.sort_values('Citations')
au_df_srtd.dtypes' and it returnsdtype: object` for all columns