【问题标题】:How to center header text in pandas dataframe?如何在熊猫数据框中居中标题文本?
【发布时间】:2019-11-16 09:38:10
【问题描述】:

如何使用命令 df.head() 将 pandas 数据框中的标题文本居中?现在对齐在右边,如何改变它? 我在 jupyterlab 1.0 中使用 Python 3.6

代码:

pd.set_option('colheader_justify', 'center')

不适用于 df.head() 命令。替代品?

【问题讨论】:

    标签: python pandas jupyter-lab


    【解决方案1】:

    用途:

    pd.set_option('colheader_justify', 'center')
    

    option docs

    这是一个例子:

    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
    

    【讨论】:

    • 但如果我写:df.head() 什么都不会改变
    猜你喜欢
    • 2019-10-05
    • 2018-10-23
    • 1970-01-01
    • 2016-08-09
    • 2020-12-28
    • 2020-01-11
    • 1970-01-01
    • 2020-07-18
    • 2013-10-23
    相关资源
    最近更新 更多