如何使用chrome打开Pandas数据框?

2024-04-25 22:43:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个熊猫数据帧,我想样式和转换为html。我想改变的东西,如文本颜色,背景色,文本对齐,并能够打开与铬。你知道吗

我已经试过了:

th_props = [
    ('font-size', '11px'),
    ('text-align', 'center'),
    ('font-weight', 'bold'),
    ('color', '#7e7bba'),
    ('background-color', '#d690b6')
]

# Set CSS properties for td elements in dataframe
td_props = [
    ('font-size', '11px')
]

# Set table styles
styles = [
    dict(selector="th", props=th_props),
    dict(selector="td", props=td_props)
]

(df_final.style
 .format({'total_amt_usd_pct_diff': "{:.2%}"})
 .set_table_styles(styles))
df_final.to_html("report.html")

没有错误。我只是在HTML文件中没有看到任何变化。你知道吗


Tags: 文本dfsizehtmltablepropsselectordict