如何设置 pandas 数据框数据左/右对齐? [英] How to set the pandas dataframe data left/right alignment?

查看:445
本文介绍了如何设置 pandas 数据框数据左/右对齐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用pd.set_option("display.colheader_justify","right")设置列标题.但是我找不到pd.describe_option()的数据选项.

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().

如何在数据框内设置数据显示的每一列的左对齐或右对齐?或者,是否可以为整个行数据显示定义格式模板?

How to set the data within a dataframe display left or right alignment for each column? Or, is it possible to define a format template for the whole row data display?

推荐答案

如果要在Jupyter Notebook中更改显示,可以使用

If you want to change the display in a Jupyter Notebook, you can use the Style feature.

# Test data
df = DataFrame({'text': ['foo', 'bar'],
                 'number': [1, 2]})

df.style.set_properties(**{'text-align': 'right'})

这篇关于如何设置 pandas 数据框数据左/右对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆