I have a dataframe that I am exporting to Excel. I would also like to style it before the export.
I have this code which changes the background color and text color and works fine, but I would like to add to it:
df.style.set_properties(**{'background-color': 'black',
'color': 'lawngreen',
'border-color': 'white'}).to_excel(writer, sheet_name='Sheet1', startrow=rowPos, float_format = "%0.5f")
I need columns with strings and dates to have a white text color, and then positive numbers to be green and negative numbers to be red. I pulled these styles directly from pandas documentation on styling since I have never used it before, and am unsure how to achieve these results.
Lets say my dataframe looks like this:
StartDate ExpiryDate Commodity Quantity Price Total
--------- ---------- ---------- ------- ----- -----
02/28/2024 12/28/2024 HO 10000 -3.89 -38900
02/28/2024 12/28/2024 WPI 10000 4.20 42000
how could I achieve what I am looking for?

I'd break it down into three steps (see the comments
#) :Output :
Used CSS :