python - Multiindex print 2nd level index labels on right side of a table -


taking example http://pandas.pydata.org/pandas-docs/stable/advanced.html

in [10]: arrays = [np.array(['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux']),    ....:           np.array(['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two'])]    ....:   in [11]: s = pd.series(np.random.randn(8), index=arrays)  in [13]: df = pd.dataframe(np.random.randn(8, 4), index=arrays)  in [14]: df out[14]:                  0         1         2         3 bar 1 -0.424972  0.567020  0.276232 -1.087401     2 -0.673690  0.113648 -1.478427  0.524988 baz 1  0.404705  0.577046 -1.715002 -1.039268     2 -0.370647 -1.157892 -1.344312  0.844885 foo 1  1.075770 -0.109050  1.643563 -1.469388     2  0.357021 -0.674600 -1.776904 -0.968914 qux 1 -1.294524  0.413738  0.276662 -0.472035     2 -0.013960 -0.362543 -0.006154 -0.923061 

how move second index print display after last columns? this:

            0         1         2         3 bar -0.424972  0.567020  0.276232 -1.087401 1     -0.673690  0.113648 -1.478427  0.524988 2 baz  0.404705  0.577046 -1.715002 -1.039268 1     -0.370647 -1.157892 -1.344312  0.844885 2 foo  1.075770 -0.109050  1.643563 -1.469388 1      0.357021 -0.674600 -1.776904 -0.968914 2 qux -1.294524  0.413738  0.276662 -0.472035 1     -0.013960 -0.362543 -0.006154 -0.923061 2 

not quite same can call reset_index passing second level , reorder columns using fancy indexing using ix , passing list of desired column order:

in [100]: df.reset_index(level=1).ix[:,list(df) + ['level_1']]  out[100]:             0         1         2         3 level_1 bar -0.171917 -0.084470  0.568098  0.749653     1 bar  0.114017  0.474004 -0.032003  0.197596     2 baz -0.310686 -0.236696  0.471586 -0.286288     1 baz  2.014078  0.957119 -0.399487  1.109984     2 foo -0.309654  0.916766  1.207385 -0.673540     1 foo  0.442063 -0.819095  0.314201 -1.125304     2 qux  1.817970 -0.316869  1.773183 -0.097240     1 qux  0.025067  0.135640  1.054219 -0.230144     2 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -