We enjoy working on Great Tables because we want everybody to easily make beautiful tables. Tables don’t have to be boring, they really could be captivating and insightful. With every release we get closer and closer to realizing our mission and, as such, we’re happy to announce the v0.2.0 release that’s now on PyPI.
The really big feature that’s available with this release is the data_color() method. It gives you several options for colorizing data cells based on the underlying data. The method automatically scales color values according to the data in order to emphasize differences or reveal trends. The example below emphasizes large currency values with a "darkgreen" fill color.
Note that we use columns= to specify which columns get the colorizing treatment (just currency here) and the palette= is given as a list of color values. From this we can see that the 65100.0 value polarizes the data coloring process; it is "darkgreen" while all other values are "lightblue" (with no interpolated colors in between). Also, isn’t it nice that the text adapts to the background color?
The above example is suitable for emphasizing large values, but, maybe you consider the extreme value to be something that’s out of bounds? For that, we can use the domain= and na_value= arguments to gray-out the extreme values. We’ll also nicely format the currency column in this next example.
Now the very large value is in "lightgray", making all other values easier to compare. We did setting domain=[0, 50] and specifying na_color="lightgray". This caused the out-of-bounds value of 65100 to have a light gray background. Notice that the values are also formatted as currencies, and this is thanks to fmt_currency() which never interferes with styling.
Here’s a more inspirational example that uses a heavily-manipulated version of the countrypops dataset (thanks again, Polars!) along with a color treatment that’s mediated by data_color(). Here, the population values can be easily compared by the amount of "purple" within them.
from great_tables.data import countrypopsimport polars as plimport polars.selectors as cswide_pops = ( pl.from_pandas(countrypops) .filter( pl.col("country_code_2").is_in(["FM", "GU", "KI", "MH", "MP", "NR", "PW"])& pl.col("year").is_in([2000, 2010, 2020]) ) .pivot(index="country_name", on="year", values="population") .sort("2020", descending=True))( GT(wide_pops, rowname_col="country_name") .tab_header( title="Populations of Select Countries in Oceania", subtitle="Population values are from 2000, 2010, and 2020.", ) .tab_spanner(label="Total Population", columns=cs.all()) .fmt_integer(columns=["2000", "2010", "2020"]) .data_color(palette=["white", "purple"], domain=[0, 1.7e5]))
Populations of Select Countries in Oceania
Population values are from 2000, 2010, and 2020.
Total Population
2000
2010
2020
Guam
160,188
164,905
169,231
Kiribati
88,826
107,995
126,463
Micronesia (Federated States)
111,709
107,588
112,106
Northern Mariana Islands
80,338
54,087
49,587
Marshall Islands
54,224
53,416
43,413
Palau
19,726
18,540
17,972
Nauru
10,377
10,241
12,315
This was just a sampler of what you can do with the all-new data_color() method. Take a look at these pages for more information:
The Colorizing with Data page in the Get Started Guide, which provides more details on how to use data_color()
The guide on Basic Styling covers general styling (e.g., bold text, underlines, etc.) with tab_style()
To conclude, we’re happy that this new functionality is now in the Great Tables package! We hope you find it useful for your table-generation work. And we’ll keep improving upon it so that you’ll have more possibilities to make beautiful, and colorful, tables for presentation.