gt-extras
  • Intro
  • Examples
  • API Reference

On this page

  • gt-extras
  • What is gt-extras?
  • How can I use it?
  • Features
  • Contributing
  • Code of Conduct
  • License

gt-extras

What is gt-extras?

We provide a collection of helper functions to enhance tables created with the Python package great-tables.

The functions in gt-extras are designed to make it easier to add plots, icons, color gradients, and other enhancements to your tables. We wrap up common patterns and boilerplate so you can focus on your data and presentation. It is based on the R package gtExtras, which was designed with a similar goal in mind.

How can I use it?

Install the latest release from PyPI:

$ pip install gt_extras

Now we can modify a great table with a collection of gt-extras features. From plotting, to icons, to color palettes, we’ve got quite the range of ready-to-use add-ons!

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

gtcars_mini = gtcars.iloc[5:15].copy().reset_index(drop=True)
gtcars_mini["efficiency"] = gtcars_mini["mpg_c"] / gtcars_mini["hp"] * 100

(
    # Start with a standard GT
    GT(gtcars_mini, rowname_col="model")
    .tab_stubhead(label="Car")
    .cols_hide(["drivetrain", "hp_rpm", "trq_rpm", "trim", "bdy_style", "msrp", "trsmn", "ctry_origin"])
    .cols_align("center")
    .tab_header(title="Car Performance Review", subtitle="Using gt-extras functionality")

    # Add gt-extras features using gt.pipe()
    .pipe(gte.gt_color_box, columns=["hp", "trq"], palette=["lightblue", "darkblue"])
    .pipe(gte.gt_plt_dot, category_col="mfr", data_col="efficiency", domain=[0, 0])
    .pipe(gte.gt_plt_bar, columns=["mpg_c", "mpg_h"])
    .pipe(gte.gt_fa_rating, columns="efficiency")
    .pipe(gte.gt_hulk_col_numeric, columns="year", palette="viridis")
    .pipe(gte.gt_theme_538)
)
Car Performance Review
Using gt-extras functionality
Car mfr year hp trq mpg_c mpg_h efficiency
California
Ferrari
2015
553.0
557.0
2.8933092224231465 out of 5 2.8933092224231465 out of 5 2.8933092224231465 out of 5 2.8933092224231465 out of 5 2.8933092224231465 out of 5
GTC4Lusso
Ferrari
2017
680.0
514.0
1.7647058823529411 out of 5 1.7647058823529411 out of 5 1.7647058823529411 out of 5 1.7647058823529411 out of 5 1.7647058823529411 out of 5
FF
Ferrari
2015
652.0
504.0
1.687116564417178 out of 5 1.687116564417178 out of 5 1.687116564417178 out of 5 1.687116564417178 out of 5 1.687116564417178 out of 5
F12Berlinetta
Ferrari
2015
731.0
509.0
1.5047879616963065 out of 5 1.5047879616963065 out of 5 1.5047879616963065 out of 5 1.5047879616963065 out of 5 1.5047879616963065 out of 5
LaFerrari
Ferrari
2015
949.0
664.0
1.2644889357218125 out of 5 1.2644889357218125 out of 5 1.2644889357218125 out of 5 1.2644889357218125 out of 5 1.2644889357218125 out of 5
NSX
Acura
2017
573.0
476.0
3.664921465968586 out of 5 3.664921465968586 out of 5 3.664921465968586 out of 5 3.664921465968586 out of 5 3.664921465968586 out of 5
GT-R
Nissan
2016
545.0
436.0
2.9357798165137616 out of 5 2.9357798165137616 out of 5 2.9357798165137616 out of 5 2.9357798165137616 out of 5 2.9357798165137616 out of 5
Aventador
Lamborghini
2015
700.0
507.0
1.5714285714285716 out of 5 1.5714285714285716 out of 5 1.5714285714285716 out of 5 1.5714285714285716 out of 5 1.5714285714285716 out of 5
Huracan
Lamborghini
2015
610.0
413.0
2.622950819672131 out of 5 2.622950819672131 out of 5 2.622950819672131 out of 5 2.622950819672131 out of 5 2.622950819672131 out of 5
Gallardo
Lamborghini
2014
550.0
398.0
2.181818181818182 out of 5 2.181818181818182 out of 5 2.181818181818182 out of 5 2.181818181818182 out of 5 2.181818181818182 out of 5


And for a little comparison, here is the table before the gt-extras features were applied.

Show the Code
(
  GT(gtcars_mini, rowname_col="model")
    .tab_stubhead(label="Car")
    .cols_hide(["drivetrain", "hp_rpm", "trq_rpm", "trim", "bdy_style", "msrp", "trsmn", "ctry_origin"])
    .tab_header(title="Car Performance Review", subtitle="Using gt-extras functionality")
)
Car Performance Review
Using gt-extras functionality
Car mfr year hp trq mpg_c mpg_h efficiency
California Ferrari 2015 553.0 557.0 16.0 23.0 2.8933092224231465
GTC4Lusso Ferrari 2017 680.0 514.0 12.0 17.0 1.7647058823529411
FF Ferrari 2015 652.0 504.0 11.0 16.0 1.687116564417178
F12Berlinetta Ferrari 2015 731.0 509.0 11.0 16.0 1.5047879616963065
LaFerrari Ferrari 2015 949.0 664.0 12.0 16.0 1.2644889357218125
NSX Acura 2017 573.0 476.0 21.0 22.0 3.664921465968586
GT-R Nissan 2016 545.0 436.0 16.0 22.0 2.9357798165137616
Aventador Lamborghini 2015 700.0 507.0 11.0 18.0 1.5714285714285716
Huracan Lamborghini 2015 610.0 413.0 16.0 20.0 2.622950819672131
Gallardo Lamborghini 2014 550.0 398.0 12.0 20.0 2.181818181818182

For a more comprehensive guide, head over to the Get Started page, and for the most comprehensive guide, see the reference docs!

Features

  • Apply color gradients and highlights
  • Add plots to table cells for visual data representation
  • Embed FontAwesome icons
  • Use pre-built themes for quick styling
  • Utilize helper utilities for common table tasks
Warning

gt-extras is currently in development, expect breaking changes.

Contributing

If you encounter a bug, have usage questions, or want to share ideas to make this package better, please feel free to file an issue.

What you might get to consider

Some of the work that went into this project was featured on the great tables blog, if you choose to contribute hopefully that can give you a sense of the process!

Code of Conduct

Please note that the gt-extras project is released with a contributor code of conduct.
By participating in this project you agree to abide by its terms.

License

Great Tables is licensed under the MIT license.

© Posit Software, PBC.