当前位置:网站首页>数据写入excel并填充颜色
数据写入excel并填充颜色
2022-07-26 00:36:00 【Pert-】
import pandas as pd
def style_apply(content, colors, back_ground=''):
if content != None and content in colors.keys():
return 'background-color: ' + colors[content]
return back_ground
def style_color(df, colors):
return df.style.applymap(style_apply, colors=colors)
resultMap = {'A':['test1', 'test2', 'test3'], 'B':['test2', 'test4', 'test5']} #写入数据结构示例
filePath = "eee.xlsx"
compare_pd=pd.DataFrame(resultMap)
writer = pd.ExcelWriter(filePath, engine='openpyxl')#创建数据存放路径
colors = {'test1':'#ff0000', 'test2':'#ffff00'}
style_df = style_color(compare_pd, colors)
style_df.to_excel(writer, header=None, index=False, sheet_name='compare')
writer.save()#文件保存
writer.close()
边栏推荐
猜你喜欢

本地电脑架设传奇怎么开外网叫朋友一起玩?

8 tips - database performance optimization, yyds~

8个小妙招-数据库性能优化,yyds~

YOLOV2 YOLO9000

聊聊研发团队中的“人”
![[calculate the number of times that one string is equal to another string]](/img/82/db8ed70464df46c7a700c65d208fef.png)
[calculate the number of times that one string is equal to another string]

sql(基础二)

SQL time splicing problem, splicing recovery automatically truncated by the system

SQL server failed to send mail, prompting that the recipient must be specified

How to open the Internet and ask friends to play together?
随机推荐
HCIP第十三天
Research on the influence of opinion leaders based on network analysis and text mining
快速入门顺序表链表
2022/7/24 examination summary
使用LocalDate类完成日历设计
Hcip day 11
Processes and threads
What is the difference between request forwarding and request redirection?
HCIA comprehensive experiment
Compile openfoam solver with cmake
Getting started with D3D calculation shaders
使用 SAP UI5 FileUploader 控件上传本地文件试读版
测试左移和测试右移的概念
微波炉整流二极管 CL01-12
pip install --upgrade can‘t find Rust compiler
Verilog grammar basics HDL bits training 06
8个小妙招-数据库性能优化,yyds~
GOM and GEE engine black screen does not display the interface, and the solution of equipping map monsters
Analysis and practice of parameter parser handlermethodargumentresolver
【IJCAI 2022】参数高效的大模型稀疏训练方法,大幅减少稀疏训练所需资源