pandas保存style到excel文件中

更多pandas style用法请参考:https://pandas.liuzaoqi.com/doc/chapter8/style.html

示例程序

py 复制代码
import numpy as np
import pandas as pd

# 示例数据
dataframe = pd.DataFrame({
    "date": pd.date_range("2024-01-01", "2024-02-01"),
    "num": np.random.random(size=32),
})

# 样式数据
style_df = dataframe.style.applymap(lambda x: 'color:red', subset=["date"]) \
    .applymap(lambda x: 'color:green', subset=["num"])

# 保存到文件中
writer = pd.ExcelWriter("样式文件.xlsx")
style_df.to_excel(writer, index=False)
writer.close()

最后的结果如下:

相关推荐
开开心心_Every10 小时前
免费进销存管理软件:云端本地双部署
java·游戏·微信·eclipse·pdf·excel·语音识别
Hello.Reader10 小时前
PyFlink 向量化 UDF(Vectorized UDF)Arrow 批传输原理、pandas 标量/聚合函数、配置与内存陷阱、五种写法一网打尽
python·flink·pandas
Kasen's experience10 小时前
Excel 怎么快速合并同一个ID不同行的大量相同单元格
excel
mudtools11 小时前
基于.NET操作Excel COM组件生成数据透视报表
c#·.net·excel
yangminlei12 小时前
Spring Boot+EasyExcel 实战:大数据量 Excel 导出(高效无 OOM)
spring boot·后端·excel
NignSah14 小时前
Microsoft Excel World Championship 2025-2025EXCEL大赛,折纸
microsoft·excel
hhzz14 小时前
Springboot项目中使用POI操作Excel(详细教程系列1/3)
spring boot·后端·excel·poi·easypoi
林月明14 小时前
【VBA】点击一个按钮实现自动更新excel文件列数据
excel·vba·宏文件·一键数据更新
Hello.Reader15 小时前
PyFlink Table API Data Types DataType 是什么、UDF 类型声明怎么写、Python / Pandas 类型映射一文搞懂
python·php·pandas
2501_9071368215 小时前
Word题库转换Excel
word·excel·软件需求