如何使用命令df.head()在熊猫数据框中将标题文本居中放置?现在对齐在右边,如何更改? 我在jupyterlab 1.0中使用Python 3.6
代码:
Create
不要用于df.head()命令。替代方案?
答案 0 :(得分:1)
使用:
pd.set_option('colheader_justify', 'center')
以下是示例:
df = pd.DataFrame(np.array([np.random.randn(6),
np.random.randint(1, 9, 6) * .1,
np.zeros(6)]).T,
columns=['A', 'B', 'C'], dtype='float')
pd.set_option('colheader_justify', 'center')
print(df)
A B C
0 -0.600705 0.5 0.0
1 -0.195192 0.6 0.0
2 -1.227175 0.8 0.0
3 0.625125 0.7 0.0
4 -0.455949 0.3 0.0
5 -0.809112 0.7 0.0