CategoricalDtypes used in Filtering Data

CategoricalDtypes in Pandas

CategoricalDtypes can also be used for filtering.  For example, if we have low, high, and medium survey responses, we can use CategoricalDtypes to filter all responses less than or equal to medium. There are three basic steps!

  1. Create the CategoricalDtype.
  2. Apply the CategoricalDtype to the pandas Series.
  3. Filter the data.
It is just that simple.  Let's look at an example.

When we print the filtered_df, we can see we have our desired output. 

It is just that simple!

Link to Google Colab with the code!


Popular posts from this blog

Drawing Tables with ReportLab: A Comprehensive Example

Blog Topics

DataFrame groupby agg style bar