Py.Cafe

maartenbreddels/

solara-pandas-seaborn-styling

Interactive Data Styling with Pandas and Seaborn

DocsPricing
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# based on https://pandas.pydata.org/pandas-docs/version/1.1/user_guide/style.html

import solara
import seaborn as sns
import pandas as pd
import numpy as np

np.random.seed(24)
df = pd.DataFrame({'A': np.linspace(1, 10, 10)})
df = pd.concat([df, pd.DataFrame(np.random.randn(10, 4), columns=list('BCDE'))],
               axis=1)
df.iloc[3, 3] = np.nan
df.iloc[0, 2] = np.nan

cm = sns.light_palette("green", as_cmap=True)
df_styled = df.style.background_gradient(cmap=cm)
df_styled


@solara.component
def Page():
    # using Jupyter's display mechanism, just as in the notebook
    display(df_styled)