【发布时间】:2016-12-10 21:34:07
【问题描述】:
这是问题"Pandas DataFrames in Jupyter: columns of equal width and centered" 的变体。
我们如何显示一个索引数据框,除索引外,所有列都居中,索引应该左对齐?还有,我们如何控制索引的宽度和其他属性?
import pandas as pd
raw_data = {'Regiment': ['Nighthawks', 'Raptors'],
'Company': ['1st', '2nd'],
'preTestScore': [4, 24],
'postTestScore': [25, 94]}
df = pd.DataFrame(raw_data, columns = ['Regiment', 'Company', 'preTestScore', 'postTestScore']).set_index('Regiment')
d = dict(selector="th",
props=[('text-align', 'center')])
df.style.set_properties(**{'width':'10em', 'text-align':'center'})\
.set_table_styles([d])
【问题讨论】:
标签: python pandas dataframe jupyter display