xlsxwriter on python, Using conditional_format function with '3_color_scale' -
i have pandas dataframe write excel sheet. want format shows heatmap of dataframe.
i figured best way go use worksheet.conditional_format()
function {'type': '3_color_scale'}
argument.
however, noticed only colors in cells holds integers. wont color has float in it. know how fix issue?
here sample of code.
writer = pd.excelwriter(file_name, engine='xlsxwriter') df.to_excel(writer, sheet_name=selected_factor, startrow=row_location, startcol=col_location) worksheet = writer.sheets['sheet 1 testing'] worksheet.conditional_format('b8:e17',{'type': '3_color_scale'})
i on python 2.7
, using pandas version 0.15.2
.
edit
i figured out why giving me trouble, numbers being saved strings spread sheet not floats.
i don't see issue when run following example. highlights integers , floats:
import pandas pd # create pandas dataframe data. df = pd.dataframe({'data': [10, 20.5, 30, 40, 50.7, 62, 70]}) # create pandas excel writer using xlsxwriter engine. writer = pd.excelwriter('pandas_conditional.xlsx', engine='xlsxwriter') # convert dataframe xlsxwriter excel object. df.to_excel(writer, sheet_name='sheet1') # xlsxwriter workbook , worksheet objects. workbook = writer.book worksheet = writer.sheets['sheet1'] # apply conditional format cell range. worksheet.conditional_format('b2:b8', {'type': '3_color_scale'}) # close pandas excel writer , output excel file. writer.save()
output:
Comments
Post a Comment