0

I have pivot table:

        avg count
days    10d 1d  20d 3d  5d  10d 1d  20d 3d  5d
range                                       
0.1 5.9 %   1.25 %  8.27 %  3.28 %  4.42 %  1104.0  1104.0  1104.0  1104.0  1104.0
0.2 4.74 %  0.96 %  7.27 %  2.22 %  3.14 %  2274.0  2274.0  2274.0  2274.0  2274.0
0.3 4.04 %  0.73 %  6.63 %  1.82 %  2.72 %  3293.0  3293.0  3293.0  3293.0  3293.0

And would like to change the order of columns "days" to original:

['1d', '3d', '5d', '10d', '20d']

I tried:

days=['1d', '3d', '5d', '10d', '20d']
table1=table.pivot(index='range',columns='days').reindex(columns=days)

but this leads to error "TypeError: Expected tuple, got str".

How can i change or create pivot table that will have columns in non alphabetical order ['1d', '3d', '5d', '10d', '20d']?

Thank you for any tips.

cs95
  • 379,657
  • 97
  • 704
  • 746
PeterL
  • 465
  • 1
  • 6
  • 14
  • The real answer is converting the "days" column into an ordered category so you don't even have to reindex. Your question is a great example of an XY problem. – cs95 Jun 12 '19 at 20:55
  • The link deals with general column order. I am having problem to order columns in Multiindex created with pivot table. Any hint on this? – PeterL Jun 13 '19 at 10:51
  • I found the answer in this topic: https://stackoverflow.com/questions/11194610/how-can-i-reorder-multi-indexed-dataframe-columns-at-a-specific-level – PeterL Jun 13 '19 at 10:57

0 Answers0