0

I'm trying to round and color values in my Pandas table. I would round the values to one decimal and color them depending on the column alarm which is 'Yes' or 'No'.

Here's my code:

pivot_table = pd.pivot_table(df, 'value', index = ['category', 'subcategory'], columns = ['date'], fill_value='-')

def color(alarm):
  color = 'red' if df['alarm'] == 'Yes' else 'green'
  return f'color: {color}'

sm_pivot_table.style.applymap(color)

I'm still getting the error message.

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Zole72
  • 39
  • 4
  • you need to apply vector operations on a Series `... if df['alarm'] == 'Yes' else ...` is not possible as `df['alarm'] == 'Yes'` cannot evaluate unambiguously to a single boolean – mozway Apr 14 '22 at 11:35
  • Use your parameter not the column: `color = 'red' if alarm == 'Yes' else 'green'` – Henry Ecker Apr 30 '22 at 04:10

0 Answers0