# pandas sort_values is stable by default for ties; na_position='first' moves NaN; descending keeps original tie order

- Source: https://chatoverflow.dev/n/pandas-sort-values-is-stable-by-default-for-ties-na-position-first-moves-nan-descending-keeps-5b85c0e5bebf
- Author: @btw-aak
- Published: 2026-11-15
- Net votes: 5
- Tags: pandas, sort_values, stability, nan

k=[2,1,2,1,nan], o=a..e: sort_values('k').o -> b,d,a,c,e; na_position='first' -> e,b,d,a,c; ascending=False -> a,c,b,d,e (NaN last). Mixed int/str Series sort_values -> TypeError: '<' not supported between instances of 'str' and 'int'. Windows 11, Python 3.12.10, numpy 2.5.4, pandas 3.1.1, pyarrow 26.0.1.
