[Xlsxwriter] Create conditional formatting Excel sheet with pandas + xlsxwriter [pandas] Memo

Overview

Source code

The entire


# xl_If you use range,"B2:C3"Xl_range(2,2,3,3)Can be expressed as.
from xlsxwriter.utility import xl_range
import xlsxwriter
import pandas as pd
import numpy as np

#Data frame for test
df = pd.DataFrame(np.arange(0,9,1).reshape(3,3))

#workbook generation
workbook = xlsxwriter.Workbook(r'./output_storage/hoge.xlsx')
#In xlsxwriter, mode='a'Cannot be used.
writer = pd.ExcelWriter(r'./output_storage/hoge.xlsx',mode='w',engine='xlsxwriter')
sheet_name = 'hoge'

#Write a data frame to a sheet
df.to_excel(writer,sheet_name=sheet_name,startrow=0,index_label='huga')

#Conditional formatting
ws = writer.sheets[sheet_name]
ws.conditional_format(xl_range(2,2,3,3),
                {'type': '3_color_scale',
                       'min_color': "#44c242",
                       'mid_color': "#ebeb44",
                       'max_color': "#eb4444"})
writer.close()

Summary

Recommended Posts

[Xlsxwriter] Create conditional formatting Excel sheet with pandas + xlsxwriter [pandas] Memo
Create xlsx file with XlsxWriter
Create an Excel file with Python3
Dynamically create new dataframes with pandas
Draw a graph with pandas + XlsxWriter
Create an age group with pandas
Excel aggregation with Python pandas Part 1
Create "operation log" CSV formatting tool in 5 days with Python Pandas PyInstaller
Quickly create an excel file with Python #python
Excel aggregation with Python pandas Part 2 Variadic
Create Excel file with Python + similarity matrix
Create an add-in-enabled Excel instance with xlwings
[Easy Python] Reading Excel files with pandas
Create a dataframe from excel using pandas
Pandas memo
pandas memo
Create a C array from a Python> Excel sheet
[Python] How to read excel file with pandas