Code: Select all
import polars as pl
import polars.selectors as cs
from great_tables import loc, style
df = pl.DataFrame({
"id": [1, 2, 3, 4, 5],
"variable1": [15, 25, 5, 10, 20],
"variable2": [40, 30, 50, 10, 20],
"variable3": [400, 100, 300, 200, 500]
})
top3_var1 = pl.col("variable1").is_in(pl.col("variable1").top_k(3))
top3_var2 = pl.col("variable2").is_in(pl.col("variable2").top_k(3))
(
df
.style
.tab_style(
style.text(weight="bold"),
loc.body("variable1", top3_var1)
)
.tab_style(
style.text(weight="bold"),
loc.body("variable2", top3_var2)
)
)
Ich habe versucht, pl.all().top_k(3) zu verwenden, um den Prozess automatisierter zu gestalten:
Code: Select all
(
df
.style
.tab_style(
style.text(weight="bold", ),
loc.body("variable1", top3_var1)
)
.tab_style(
style.text(weight="bold"),
loc.body("variable2", top3_var2)
)
)
Mobile version