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

最后的结果如下:

相关推荐
Data-Miner11 小时前
怎么用AI给Excel去重?先核对这7条再下手,别让好数据被删错:数以轻舟方案解析
人工智能·excel
Data-Miner13 小时前
做表格数据分析的AI工具怎么选?先对一下这三个真实需求,再看哪些真能落地
人工智能·数据分析·excel
虎头金猫6 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
Xiu Yan7 天前
Python 数据分析:Pandas DataFrame 零基础入门教程
python·jupyter·pycharm·numpy·pandas
尤鸟倦7 天前
OneNote table复制到Excel遇到的各种问题
excel
2601_966949657 天前
为什么量化回测中 for 循环比 DataFrame 慢三个数量级?从向量化原理讲起
开发语言·python·pandas·股票数据·quantdash
2501_930707788 天前
使用C#代码使用条件格式为 Excel 隔行设置颜色
c#·excel
Xiu Yan8 天前
Python 数据分析:Pandas Series 零基础入门教程
python·jupyter·pycharm·numpy·pandas
leihefeng8 天前
PX04-用 Python 读 Excel 画折线图,还能直接插回 Excel 文件
python·excel
yanlaifan8 天前
Excel中指定单元格不能输入内容的方法
excel