Easiest way to create a color gradient on excel using python/pandas? -


Then I have data that I'm output to Excel file using Excel's Excel spreadsheets. After output to the entire data excel file, what is the easiest way to use conditional formatting for python programming?

I want to be able to select all filled cells in excel sheet ("in Excel") (via Python) and click on "conditional formatting"; Color scales have a gradient of colors depending on the end result values, if you do, then "heat map".

This is the data I am creating:

  writer = ExcelWriter ('data' + today + '.xls') ... data processing. . Df.to_excel (author, sheet_name = 'model', startrow = start_row, index = false)   

After writing the data, use a python to implement conditional formatting Way. To make it simple, I want the color should be a darker color than the colors of blue and more positive (& gt; 0), and the red negative values ​​(& lt; 0) and the cell white if value 0 is.

I tried xlsxwriter (hopefully expecting to modify the excel file after creating it) but in the documentation it says that "this [XLSXwriter] can not read or modify existing Excel XLSX Files. "

Please tell me if you can think of a solution or tell me in the right direction.

>

Df = pd.DataFrame (list_data) # Create a Pandas Excel author using XlsxWriter as the engine. Excel_file = 'testfile.xlsx' sheet_name = 'sheet1' author = pd. Access the XLSWRITER workbook and worksheet objects from #filefire (Axl_file, engine = 'xlsquitter') df.to_excel (author, sheet_n = sheet_name) #filefile # This is equivalent to: For self using XlsxWriter: # # Workbook = xlsxwriter.Workbook ('filename.xlsx') #Worksheet = Workbook.ADV worksheet () #Workbook = Authors.book Worksheet = Authors. Sheets [sheet_name] Apply a conditional form in the # cell range worksheet. Conditional_format ('B2: B8', {'type': '3_color_scale'}) # Panda Excel close the author and output the Excel file. Author.save ()

The output looks like this:

Enter image details here

You can see the XlsxWriter document how you can change color or other properties.

See also

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -