I built a pivot table doing this:
prima_neta = df.pivot_table(index = ["seccion"], columns = "operacion", values = "prima_pesos", aggfunc = "sum", margins=True).fillna(0)
and then tried to sort the table in descending order by 'All' column (generated by margins=True):
prima_neta.sort_values(by='All', ascending=False)
This works fine, but the 'All' total (which of course is the highest amount) at the end of the original table output is brought up to the top as first line.
I would like to sort the table in descending order, but keep the 'All' (Totals) amounts at the last line.
How can I achieve this?