Home > database >  Reordering the column name in crosstab
Reordering the column name in crosstab

Time:01-04

On a crosstab, i'm looking to reorder the columns listed on the table from "Decreased" "Increased" "Remained" to "Increased" "Remained" "Decreased". Here's an image explaining the exact required change.

[Existing order of columns with required change]

1

I'm also looking to do this for an accompanying chart.

Thank you in advance! Josh

CodePudding user response:

You can simply select the columns in the order you want. E.g.:

z = pd.crosstab(...)
z[['Increased', 'Remained', 'Decreased']]

CodePudding user response:

It seems, that pandas is sorting this in alphabetical order. There is no hint in the docs how one could rearrange this.

So i would simply rename it like 0_Increased, 1_Remained, 2_Decreased. Maybe this is working for you?

  •  Tags:  
  • Related