shape: (6, 2)
| Student | Grade |
|---|---|
| str | i64 |
| "Spencer" | 93 |
| "Emily" | 88 |
| "Hannah" | 73 |
| "Aria" | 69 |
| "Mona" | 55 |
| "Paige" | 89 |
filter
Joram Mutenge
2025-12-15
If you are analyzing data with Polars, it is almost impossible to complete an analysis without filtering. Data analysis usually involves selecting some rows from a dataframe while excluding others. Below is a dataframe of students and their grades.
| Student | Grade |
|---|---|
| str | i64 |
| "Spencer" | 93 |
| "Emily" | 88 |
| "Hannah" | 73 |
| "Aria" | 69 |
| "Mona" | 55 |
| "Paige" | 89 |
To get the row showing the student with the highest grade, you can use the filter method together with the max function, as shown below:
You can also use filter to get the opposite of a specified value by using the “not equal to” operator (!=):
| Student | Grade |
|---|---|
| str | i64 |
| "Emily" | 88 |
| "Hannah" | 73 |
| "Aria" | 69 |
| "Mona" | 55 |
| "Paige" | 89 |
You can achieve the same result as in the previous example by using the negation symbol ~:
| Student | Grade |
|---|---|
| str | i64 |
| "Emily" | 88 |
| "Hannah" | 73 |
| "Aria" | 69 |
| "Mona" | 55 |
| "Paige" | 89 |
Check out my Polars course to learn more clever ways to analyze your data.