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!
- Create the CategoricalDtype.
- Apply the CategoricalDtype to the pandas Series.
- 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!
Comments
Post a Comment