'Conditional formatting scale colouring with 0 value as white openpyxl

When I apply conditional formatting:

            ws.conditional_formatting.add(
                f'{col_xlsx}2:{col_xlsx}{len(df) + 2}',
                ColorScaleRule(start_type='min', start_color=Color(blue_color),
                               mid_type='formula', mid_value=0, mid_color=Color(white_color),
                               end_type='max', end_color=Color(red_color))
            )

I obtain what I want except for the cases when 0 is the only value in the column. How can I make sure that 0's stay white?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source