great_tables
  • Get Started
  • Examples
  • Reference
  • Blog

On this page

  • Examples

from_column

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"])
    )
)
x color
1 red
2 blue

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"])
    )
)
x color
1 red
2 blue