def mdf_format_vertical_headers(df,height_str='100px',transform_str='rotate(-90deg)',precision=3):
"""Display a dataframe with vertical column headers. Returns a styler object - Only affects display so cant use .head() etc
rotate(-90deg) - rotates the text by 90 degrees. default. TBD why negative numbers
rotate(-80deg) - rotates the text by 80 degrees
"""
styles = [dict(selector="th", props=[('width', '40px')]),
dict(selector="th.col_heading",
props=[("writing-mode", "horizontal"),
('transform',transform_str ),
('height', height_str),
('vertical-align', 'top')])]
return (df.fillna('').style.set_table_styles(styles).format(precision=precision))
2条答案
按热度按时间bxjv4tth1#
您不能尝试修改数据框的HTML样式,请尝试调整hegiht属性:
rryofs0p2#
可能无法回答最初的“multiindex”问题,但在使用table_style时,对于格式化标题行和显示精度很有用