Binning

Learn how to use binning in Altair.

Binning involves grouping data into intervals or bins and summarizing the data within each bin. This technique transforms continuous variables into categorical variables, allowing us to see patterns and trends more clearly. Binning is especially useful when dealing with large datasets, because it can reduce the complexity of the data and make it easier to interpret.

In Altair, we can implement binning through the bin parameter.

How to use binning in Altair

To use binning, set the bin parameter to True.

Consider the following example, which uses the sample dataset and creates a horizontal bar chart in Altair. The chart displays the distribution of values of the Values column in the dataset. The chart shows the count of values in each bin, with the bins defined using the bin parameter.

Get hands-on with 1200+ tech skills courses.