栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用python / pandas在excel上创建颜色渐变的最简单方法?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用python / pandas在excel上创建颜色渐变的最简单方法?

这是一个如何将条件格式应用于Pandas创建的XlsxWriter Excel文件的示例:

import pandas as pd# Some sample data to plot.list_data = [30, 40, 50, 40, 20, 10, 5]# Create a Pandas dataframe from the data.df = pd.Dataframe(list_data)# Create a Pandas Excel writer using XlsxWriter as the engine.excel_file = 'testfile.xlsx'sheet_name = 'Sheet1'writer = pd.ExcelWriter(excel_file, engine='xlsxwriter')df.to_excel(writer, sheet_name=sheet_name)# Access the XlsxWriter workbook and worksheet objects from the dataframe.# This is equivalent to the following using XlsxWriter on its own:##    workbook = xlsxwriter.Workbook('filename.xlsx')#    worksheet = workbook.add_worksheet()#workbook = writer.bookworksheet = writer.sheets[sheet_name]# Apply a conditional format to the cell range.worksheet.conditional_format('B2:B8', {'type': '3_color_scale'})# Close the Pandas Excel writer and output the Excel file.writer.save()

输出如下所示:

请参阅有关条件格式的XlsxWriter文档,以了解如何更改颜色或其他属性。

另请参阅使用Python
Pandas和XlsxWriter



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/668339.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号