How to set the pandas dataframe data left/right alignment?

后端 未结 6 988
礼貌的吻别
礼貌的吻别 2020-11-30 05:23

I use pd.set_option(\"display.colheader_justify\",\"right\") to set the column header. But I can\'t find the option for data by pd.describe_option()

6条回答
  •  悲&欢浪女
    2020-11-30 06:01

    The answer given by @Romain is great but I would like to summarize some comments:

    # Test data
    df = DataFrame({'text': ['foo', 'bar'],'number': [1, 2]})
    
    dfStyler = df.style.set_properties(**{'text-align': 'left'})
    dfStyler.set_table_styles([dict(selector='th', props=[('text-align', 'left')])])
    

    will align all table text and the column headers as well.

提交回复
热议问题