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

最后的结果如下:

相关推荐
HealthScience几秒前
vscode使用Excel插件导致codex插件无法粘贴图片
服务器·vscode·excel
性野喜悲1 小时前
python将excel中的链接转成图片并替换链接展示在excel中【将pdf的第一页插入excel并将对应信息获取到插入签名等位置】
开发语言·python·excel
黑贝是条狗4 小时前
Excel批量处理工具
linux·运维·excel
WL_Aurora4 小时前
Excel打开CSV文件中文乱码问题解决方案
excel
百事牛科技4 小时前
Excel安全入门:如何设置和取消打开密码
windows·安全·excel
deephub5 小时前
Feature Engineering 实战:Pandas + Scikit-learn的机器学习特征工程的完整代码示例
人工智能·python·机器学习·pandas·scikit-learn
jllllyuz6 小时前
VC++ 读写 Excel 文件实现
开发语言·c++·excel
fengyehongWorld6 小时前
Excel 函数式编程相关的公式
excel
星空椰6 小时前
Python 使用飞书 API 获取子部门列表接口信息
python·pandas·飞书
七夜zippoe21 小时前
Python RESTful API设计终极指南:从理论到企业级实战
开发语言·python·http·pandas·restful api