0

I would like to have all numbers rounded to two decimal places in my pandas table which I'm looking to visualise. When I do df.round(2) I get the desired output:

Rounded to 2 decimal places as desired

However, when I then apply a conditional styling to this table, I end up with trailing zeros.

df.round(2).style.apply(lambda x: ['background: cyan' if 1>x['target'] else 'background: yellow' for v in x], axis=1)

Undesired: Leading zeros

Any ideas how I can get rid of the trailing zeros while applying the conditional background style? Thanks in advance.

noob
  • 5,954
  • 6
  • 20
  • 32
  • 1
    Shouldn't you set the `precision` from your actual format rather than rounding it before hand ? https://pandas.pydata.org/pandas-docs/stable/user_guide/style.html – Zeitounator Jan 23 '22 at 11:39
  • Thanks both, the answers helped! Apologies, I should have carried out a better search on here. – noob Jan 23 '22 at 11:44

0 Answers0