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()

最后的结果如下:

相关推荐
Metaphor69214 小时前
使用 Python 在 Excel 文件中查找并替换
python·excel
xiaomin-Michael15 小时前
EXCEL pivot table
excel
包子源15 小时前
PDF 转 Word/Excel 全链路实战:Next.js + 阿里云文档智能
pdf·word·excel
Java知识技术分享16 小时前
excel动态表头实现+异步使用
java·spring·excel
tedcloud1231 天前
academic-research-skills部署教程:构建AI辅助科研环境
服务器·人工智能·word·excel·dreamweaver
wtsolutions1 天前
Sheet-to-Doc Excel Add-in Released, Install Directly from Microsoft AppSource
microsoft·excel
开开心心就好1 天前
完美兼容Office格式的免费办公套件
windows·均值算法·计算机外设·word·excel·csdn开发云·图搜索算法
未来之窗软件服务2 天前
Excel 物流货运记账表模板【万象EXCEL(二十七)】—东方仙盟
excel·仙盟创梦ide·东方仙盟·万象excel
Land03292 天前
Excel 自动化 RPA 教程:批量处理、报表生成与数据汇总实战,离线方案详解
自动化·excel·rpa