gt-extras
  • Get Started
  • API Reference
  1. Icons and Images
  2. gt_fa_rating
  • API Reference
  • Plotting
    • gt_plt_bar
    • gt_plt_dot
    • gt_plt_conf_int
  • Colors
    • gt_highlight_cols
    • gt_hulk_col_numeric
    • gt_color_box
  • Themes
    • gt_theme_538
    • gt_theme_espn
    • gt_theme_guardian
    • gt_theme_nytimes
    • gt_theme_excel
    • gt_theme_dot_matrix
    • gt_theme_dark
    • gt_theme_pff
  • Icons and Images
    • fa_icon_repeat
    • gt_fa_rating
  • HTML Helpers
    • gt_hyperlink
    • with_tooltip

On this page

  • Parameters
  • Returns
  • Example
  1. Icons and Images
  2. gt_fa_rating

gt_fa_rating

gt_fa_rating(
    gt,
    columns,
    max_rating=5,
    name='star',
    primary_color='gold',
    secondary_color='gray',
    height=20,
)

Create icon ratings in GT cells using FontAwesome icons.

This function represents numeric ratings in table column(s) by displaying a row of FontAwesome icons (such as stars) in each cell. Filled icons indicate the rating value, while unfilled icons represent the remainder up to the maximum rating. Hover the icons to see the original numeric rating.

Parameters

gt : GT

A GT object to modify.

columns : SelectExpr

One or more columns containing numeric rating values.

max_rating : int = 5

The maximum rating value (number of total icons).

name : str = 'star'

The FontAwesome icon name to use.

primary_color : str = 'gold'

The color for filled icons.

secondary_color : str = 'gray'

The color for unfilled icons.

height : int = 20

The height of the rating icons in pixels.

Returns

: GT

A GT object with icon ratings added to the specified column(s).

Example

from random import randint
from great_tables import GT
from great_tables.data import gtcars
import gt_extras as gte

gtcars_mini = (
    gtcars
    .loc[8:15, ["model", "mfr", "hp", "trq", "mpg_c"]]
    .assign(rating=[randint(1, 5) for _ in range(8)])
)

gt = (   
    GT(gtcars_mini, rowname_col="model")
    .tab_stubhead(label="Car")
)

gt.pipe(gte.gt_fa_rating, columns="rating", name="r-project")
Car mfr hp trq mpg_c rating
F12Berlinetta Ferrari 731.0 509.0 11.0
1.0 out of 5 1.0 out of 5 1.0 out of 5 1.0 out of 5 1.0 out of 5
LaFerrari Ferrari 949.0 664.0 12.0
2.0 out of 5 2.0 out of 5 2.0 out of 5 2.0 out of 5 2.0 out of 5
NSX Acura 573.0 476.0 21.0
4.0 out of 5 4.0 out of 5 4.0 out of 5 4.0 out of 5 4.0 out of 5
GT-R Nissan 545.0 436.0 16.0
5.0 out of 5 5.0 out of 5 5.0 out of 5 5.0 out of 5 5.0 out of 5
Aventador Lamborghini 700.0 507.0 11.0
1.0 out of 5 1.0 out of 5 1.0 out of 5 1.0 out of 5 1.0 out of 5
Huracan Lamborghini 610.0 413.0 16.0
4.0 out of 5 4.0 out of 5 4.0 out of 5 4.0 out of 5 4.0 out of 5
Gallardo Lamborghini 550.0 398.0 12.0
5.0 out of 5 5.0 out of 5 5.0 out of 5 5.0 out of 5 5.0 out of 5
Continental GT Bentley 500.0 487.0 15.0
5.0 out of 5 5.0 out of 5 5.0 out of 5 5.0 out of 5 5.0 out of 5
fa_icon_repeat
gt_hyperlink