'Unable to color my cells in pandas using styler

def coloring_deduction_count(df):
  
    x1 = [...]
    x2 = [...]


    for column in df:

        if (is_numeric_dtype(df[column])):
            if not math.isnan((df.loc[df.Params == 'Outlier if x>',column])):
                for element in df[column]:

                    if not (math.isnan(element)):
                        if (element > x1[column]) or (element < x2[column]):

                            color = 'red'
                       

    return 'background-color: %s' % color

df.style.applymap(coloring_deduction_count)
df.to_excel(writer, sheet_name = 'Calculations')

x1 and x2 are lists , i want to color in red the elements that get past the last if, otherwise no change in colors, what's currently happening is that the excel is being written to the writer but no coloring.



Sources

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

Source: Stack Overflow

Solution Source