from_column(column, na_value=None, fn=None)
Specify that a style value should be fetched from a column in the data.
Examples
import pandas as pd
from great_tables import GT, exibble, from_column, loc, style
df = pd.DataFrame({"x": [1, 2], "color": ["red", "blue"]})
(
GT(df)
.tab_style(
style=style.text(color=from_column("color")),
locations=loc.body(columns=["x"])
)
)
If you are using polars, you can just pass polars expressions in directly:
import polars as pl
from great_tables import GT, exibble, from_column, loc, style
df_polars = pl.from_pandas(df)
(
GT(df_polars)
.tab_style(
style=style.text(color=pl.col("color")),
locations=loc.body(columns=["x"])
)
)