简体   繁体   中英

sort_values versus sort giving different answers, but sort_values is the correct answer

I'm wondering what the difference between these two snippets of code could be?

New_Series = pd.Series(df['avg']).sort(axis=0, ascending=False, 
                                       kind='quicksort', na_position='last', 
                                       inplace=True)
New_Series = pd.Series(df['avg']).sort_values(axis=0, ascending=False, 
                                              kind='quicksort', na_position='last', 
                                              inplace=True)

sort_values returns the correct series, but sort returns None .

Is there a difference between these two that makes sort differently from sort_values ?

Apart from the fact that sort is deprecated, it returns None when you use inplace=True

sort_values still returns the self updated dataframe is you use that argument as you can see in frame.py source code:

    if inplace:
        return self._update_inplace(new_data)
    else:
        return self._constructor(new_data).__finalize__(self)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM