objectif
Appliquer formattage et heatmap sur DataFrame (Jupyter).
code minimal
import pandas as pd
import numpy as np
df = pd.DataFrame(np.arange(9).reshape(3,3))
styler = df.style.format("{:.1f}")
print(isinstance(styler, pd.io.formats.style.Styler))
utilisation
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.default_rng(0).normal(size=(5,5)))
styler = df.style.background_gradient(axis=None)
print(styler is not None)
variante(s) utile(s)
import pandas as pd
df = pd.DataFrame({"p":[0.1,0.2345]})
styler = df.style.format({"p":"{:.2%}"})
print(styler is not None)
notes
- Affichage interactif en notebook; pour fichiers, exporter HTML.