Could you please help me with sorting the values by a column in a pivot table in Python?
I’ve tried to sort the values in a dataframe before I created the pivot table, but, unfortunately, it didn’t help me.
So, here I have the sorted data by date column and ascending=False:
Then I created a pivot table, and here is the result:
Please, help me to sort my pivot table by a date column where ascending=False.
>Solution :
Remove [] from index, columns, values for remove MultiIndex and then sorting columns by DataFrame.sort_index:
df = (alert_.pivot_table(index='col1', columns='col2', values='col3')
.sort_index(axis=1, ascending=False))

