For a new column in pandas, I want to set every value in red when I have the value 1. comp_df.loc[comp_df["comp_ad"] == 1].
I already tried it, but I have an error
comp_df.style.applymap(lambda x: "background-color: red" if comp_df['comp_ad'] == 1)
Thanks in advance!
CodePudding user response:
Use if-else
statement with subset
parameter for test column comp_ad
:
(comp_df.style
.applymap(lambda x: "background-color: red" if x == 1 else "", subset=['comp_ad'])
.to_excel('styled.xlsx', engine='openpyxl'))