How can I render a Pandas df where one of the columns' style.bar.color
property is computed based on some condition?
Example:
df.style.bar(subset=['before', 'after'], color='#ff781c', vmin=0.0, vmax=1.0)
Instead of having both columns highlight with #ff781c
, I'd like one of the columns (df['before']
) to remain that same constant color, and the other column (df['after']
) to be computed as:
def compute_color(row):
if row['after'] >= row['before']:
return 'red'
else:
return 'green