Why can't I apply sort_values to a dataframe more than once?
When you use .sort_values(['a', 'b']) you are first sorting the dataframe by the column a, and then within those sortings, sorting by b. Think of it almost as grouping by the first sort, then sorting within those groupings. If there was a c, it would sort the c column within the a b groups.
If you do .sort_values('a').sort_values('b') you are sorting the dataframe by a and then taking that returned dataframe, and "starting over" by sorting it by b basically destroying the previous sorting of a. using ['a', 'b'] keeps each of the sorts and sorts within.
Say for example I have a multi-column dataframe. I want to arrange my data by sorting column a ascending first, then by column b ascending also.
I am able to achieve this by the ff. code: df.sort_values(['b','a']). Note the reversed order of the arguments.
My question is, why doesn't df.sort_values('a').sort_values('b') work?