I have created a df where the values are *”Yes”, “No” and “Maybe”.*
I would like to make this cells colorful before saving in excel. If I use the library xlwt, I have something like this:
sheet2.write(row, col, str('Allowed'), style)
However, I don’t want to open the excel again, which it is already created with pandas in order to go through and fill it with my colors. I would like to save my dataframe already with the desired colors formatted in excel.
My dataframe is something like this:
My desired output is:
Any suggestions on how to do this?
something like this?
def color_df(val): if val == 'Yes': color = 'red' elif val == 'Maybe': color = 'Orange' else: color = 'Blue' return 'color: %s' % color df = df.style.applymap(color_df).to_excel(path_var + 'styled.xlsx', engine='xlsxwriter')