I want to know how to apply multiple style on part of my df. I need to import the table on excel. I read all the doc
With this code I manage to color (as I want) only the columns "Différence", but I want to keep the column "Avant".
main_tableau().iloc[:, main_tableau().columns.get_level_values(1)=='Différence'].style.applymap(lambda x: f"background-color: {'#FFFFA7' if not isinstance(x, numbers.Number) else '#28D1C5' if x > 2 else '#FFC33C' if x < -2 else 'white'}").format(precision=2)
Here is what I don't want, the columns 'Avant' with style.
I try things like this to see if I manage tp apply style on my columns "différence" but it don't work: AttributeError: 'Styler' object has no attribute 'iloc'
df = df.style.applymap(lambda x: f"background-color: {'#FFFFA7' if not isinstance(x, numbers.Number) else '#28D1C5' if x > 2 else '#FFC33C' if x < -2 else 'white'}")\
.applymap(lambda v: 'opacity: 20%;' if v in (main_tableau().iloc[:, main_tableau().columns.get_level_values(1)=='Différence']) else None).format(precision=2)
The result I want :
CodePudding user response:
You can apply different styles to different
Please note that indices must be unique for this to work, but at least in the example you provided I think this is the case.