I have an arbitrary dataframe, something like this:
import pandas as pd
df = pd.DataFrame.from_dict({'col_1': [3, 2, 1, 0], 'col_2': ['a', 'b', 'c', 'd'], 'col_3':[100,-100, 50, -50,]})
df
is there a way to change the formatting for each item in such a way that larger values within a column are one color and smaller values are another? Preferably the implementation would be:
- something brief
- able to be applied to most simple dataframes
- robust enough to handle different datatypes
as an example, Excel has conditional formatting which looks like this:
It doesn't do anything meaningful with strings or chars, but otherwise behaves nicely