Skip to main content
 首页 » 编程设计

python之在 Pandas 风格渲染中格式化日期

2024年10月17日6sxdcgaq8080

我有一个包含三列的 Pandas 数据框,其中第一列是日期。为了生成 html 输出,我使用了这个:

html_string = df.style.format({'second': "{:0,.0f}",third: "{:0,.0f}"}).set_table_styles(styles).render() 

如何指定日期的格式以及......类似的东西:

html_string = df.style.format({'Date': "%Y.%m",'second': "{:0,.0f}",third: "{:0,.0f}"}).set_table_styles(styles).render() 

请您参考如下方法:

你可以这样做:

html_string = df.style.format({'Date': "{:%Y.%m}", 
                               'second': "{:0,.0f}", 
                               'third': "{:0,.0f}"}).set_table_styles(styles).render()