From the course: Using Python with Excel

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Conditional formatting

Conditional formatting

Did you know that humans process visual data thousands of times faster than text? Adding conditional formatting to your workbook really aids in comprehension. And the best part is, you can build conditional workbooks in Excel right from Python. Open the demo file for this lesson, 03_03_demo. This time you will have the tips data set loaded in from Seaborn. First thing to print here is tips.style. At first, this just looks like a regular old DataFrame that you've seen throughout the course. It turns out that it's actually possible to add custom styles such as conditional formatting to a DataFrame, and those results will be visible when you print this style attribute. For example, I want to highlight all of the cells where tip is greater than three as green. To do this, I'll create a function, highlight_cells(), then map that function to the desired part of the DataFrame, which is the tip column. Here it goes. def highlight_cells(val): then set color to green if the value is greater…

Contents