Filtering consists of two steps:
- Creating a filter mask to check which elements in a data frame meet a certain condition.
- Apply the filter mask to a data frame to get all the elements in the filtered positions.
Using Filter masks¶
We want to extract only the data for cold days, which we consider to be below 10 degrees Celsius. For this purpose we generate a series to use as a filter mask:
We can apply this filter to our dataframe:
All in one¶
These steps often get combined into one:
A filter mask can be inverted by using the
~ prefix operator:
- Combining selections with a boolean comparison generates a filter mask which can then again be used to filter a dataframe