I have some data which contains columns for the actual value and then the original target value
dimension | metric_actual | metric_target | metric2_actual | metric2_target
A 16.41 20.00 68.54% 72.00%
B 17.39 18.00 63.87% 60.00%
Ideally, I want the cell to have red text if the metric_actual is less than the target, and to have green text if it is greater than the target.
I would like to output a dataframe into an email using the .style options. I can't seem to figure out how to do this on a row by row basis though if the target is potentially different for each row.
http://pandas.pydata.org/pandas-docs/stable/style.html
These functions work but only if I have one static column. My issue is that the targets are different for the same metric for each row in the data.
def color_negative_red(value, target):
color = 'red' if value < target else 'green'
return 'color: %s' % color
Edit the issue is that I get 'truth is ambiguous errors':
df.style.applymap(color_negative_red, target=df['metric_target'], subset=['metric_actual']
I feel like this should be possible but I need to compare each value per row to the corresponding target value in that same row.