Pretty print pandas: how to set the columns as displayed rows (and rows as displayed columns)?

1k views Asked by At

Any ideas on how to set the columns as displayed rows, and hence displaying the rows as columns in pandas?

Currently printing a dataframe outputs something like this:

      K      T  best_testing_rmse  best_training_rmse  chan_out_dim  \
48   15  20000  1.24502685         1.24942538          15             
217  15  20000  1.25521732         1.24871174          15             

     dropout_p g_hid g_in g_latent    g_rij  \
48   0.1        tanh  elu  linear   sigmoid   
217  0.1        tanh  elu  linear   sigmoid   

                           harvest_dir  hid_dim  input_dropout_p  \
48   ./harvest_autorec_20170103_175735  50       0.1               
217  ./harvest_autorec_20170103_175730   50       0.1               

     last_testing_rmse  last_training_rmse        lr  max_epoch  \
48   1.52006088         1.52138316          0.000002  1403        
217  1.31366942         1.30483602          0.000002  1056        

     minibatch_size  n_epochs  n_hid_layers optimizer preprocessing_type  \
48   1               20000     1             gpu_omp   zscore              
217  1               20000     1             gpu_omp   zscore              

    regression_error_coef regression_type  regularization_lambda  \
48   0.5                   item            0.001                   
217  0.5                   item            0.001                   

     regularization_latent_kl stochastic_prediction            upd  
48   0.5                       False                 adam_symbolic  
217  0.5                       False                 adam_symbolic  

This is particularly inconvenient. Much better view this table rotated of 90 degrees.

1

There are 1 answers

0
EdChum On BEST ANSWER

What you're asking for is to transpose which can be called using .T which rotates the df so that the columns becomes rows and vice versa:

In [31]:
df = pd.DataFrame(np.random.randn(5,3), index=list('vwxyz'), columns=list('abc'))
df

Out[31]:
          a         b         c
v  0.218951 -0.716086  0.620063
w -0.672559  0.311909  0.326861
x  0.866325 -0.591517 -0.387572
y -0.749873  1.645110 -1.185780
z -0.796720 -1.974399  0.546645

In [32]:
df.T

Out[32]:
          v         w         x         y         z
a  0.218951 -0.672559  0.866325 -0.749873 -0.796720
b -0.716086  0.311909 -0.591517  1.645110 -1.974399
c  0.620063  0.326861 -0.387572 -1.185780  0.546645