gpt4 book ai didi

python - 漂亮的打印 Pandas : how to set the columns as displayed rows (and rows as displayed columns)?

转载 作者:太空宇宙 更新时间:2023-11-03 15:49:09 27 4
gpt4 key购买 nike

关于如何将列设置为显示的行,从而在 pandas 中将行显示为列,有什么想法吗?

当前打印数据帧输出如下:

      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

这特别不方便。这张旋转 90 度的 table 看得更清楚。

最佳答案

您要求的是转置,可以使用 .T 调用它它旋转 df 以使列变成行,反之亦然:

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

关于python - 漂亮的打印 Pandas : how to set the columns as displayed rows (and rows as displayed columns)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41467773/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com