API to style categorical variables
See original GitHub issueIt is often useful to style columns having a pd.CategoricalDtype
, by either:
- being supplied a mapping from category name/code to background colour.
- being supplied a mapping from category name/code to Styler.
- selecting
len(dtype.categories)
colours from a matplotlib colormap (qualitative or otherwise).
So for example we might allow for:
StyleFrame(df).add_categorical_conditional_formatting(style_map={"a": Styler(font_color="red"), "b": Styler(font_color="green"), "c": Styler(font_color="blue")})
or
StyleFrame(df).add_categorical_conditional_formatting(style_bg_cmap="Pastel1"})
which would perform the following for each column
cmap = matplotlib.cm.get_cmap(style_bg_cmap)
col_style_map = dict(zip(col.dtype.categories, cmap(len(col.dtype.categories))))
Conditional formatting would be applied using a CellIsRule("=", category)
for each category value in each column in range.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Fitting models using R-style formulas - Statsmodels
Since version 0.5.0, statsmodels allows users to fit statistical models using R-style formulas. Internally, statsmodels uses the patsy package ...
Read more >Categorical Data — xgboost 1.7.2 documentation
The basic idea is create dataframe with category feature type, and tell XGBoost to use it by setting the enable_categorical parameter. See Getting...
Read more >3 Ways to Encode Categorical Variables for Deep Learning
How to integer encode and one hot encode categorical variables for modeling. ... How to Use the Keras Functional API for Deep Learning....
Read more >Unique types | Documentation - ArcGIS Developers
Different APIs have different levels of support for data-driven visualization. Unique types, Class breaks, Visual variables, Time, Multivariate, Predominance ...
Read more >Visualizing categorical data — seaborn 0.12.1 documentation
If one of the main variables is “categorical” (divided into discrete groups) it may be helpful to use a more specialized approach to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ah, I see.
The current API does support conditional formatting, but only using
ColorScaleRule
(wrapped byStyleFrame.add_color_scale_conditional_formatting
).However, the above example can be implemented without it, using quite an explicit code:
generating
This issue has been automatically marked as stale because it has not had activity in the last 60 days.