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

最后的结果如下:

相关推荐
虎头金猫1 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
Xiu Yan1 天前
Python 数据分析:Pandas DataFrame 零基础入门教程
python·jupyter·pycharm·numpy·pandas
尤鸟倦2 天前
OneNote table复制到Excel遇到的各种问题
excel
2601_966949652 天前
为什么量化回测中 for 循环比 DataFrame 慢三个数量级?从向量化原理讲起
开发语言·python·pandas·股票数据·quantdash
2501_930707782 天前
使用C#代码使用条件格式为 Excel 隔行设置颜色
c#·excel
Xiu Yan2 天前
Python 数据分析:Pandas Series 零基础入门教程
python·jupyter·pycharm·numpy·pandas
leihefeng2 天前
PX04-用 Python 读 Excel 画折线图,还能直接插回 Excel 文件
python·excel
yanlaifan3 天前
Excel中指定单元格不能输入内容的方法
excel
gCode Teacher 格码致知3 天前
Pandas教学-6:coerce详解
python·pandas
babe小鑫3 天前
信息与计算科学专业应届生面试 怎么证明自己能解决业务问题
学习·r语言·excel