So I have data that I am outputting to an excel file using pandas' ExcelWriter. After the entire data is outputted to the Excel file, what is the easiest way to apply conditional formatting to it programmatically using Python?
I want to be able to do the equivalent (through Python) of selecting (in Excel) all the filled cells in the Excel sheet and clicking on "Conditional Formatting" > Color Scales. The end result is a gradient of colors based on the values, a "heat map" if you will.
This is what I am doing to generate the data:
writer = ExcelWriter('Data' + today +'.xls')
... processing data ...
df.to_excel(writer, sheet_name = 'Models', startrow = start_row, index=False)
After the data is written, I need a way to apply the conditional formatting using python. To make it simple, I want the colors to be darker shades of blue the more positive (>0) the values are and to be darker shades of red the more negative the values are (<0) and the cell to be white if the value is 0.
I tried looking into xlsxwriter (in hopes of being able to modify the excel file after creating it) but in the documentation it says that "It [XLSXwriter] cannot read or modify existing Excel XLSX files."
Please let me know if you can think of a solution or point me in the right direction.