Is it feasible to sort pandas dataframe by values of a column, but also by index?
If you sort a pandas dataframe by values of a column, you can get the resultant dataframe sorted by the column, but unfortunately, you see the order of your dataframe's index messy within the same value of a sorted column.
So, can I sort a dataframe by a column, such as the column named count
but also sort it by the value of index? And is it also feasible to sort a column by descending order, but whereas sort a index by ascending order?
I know how to sort multiple columns in dataframe, and also know I can achieve what I'm asking here by first reset_index()
the index and sort it, and then create the index again. But is it more intuitive and efficient way to do it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…