It keeps rows where the cyl column is equal to 4, AND the gear column is equal to five.
Filters with OR conditions
In order to keep a row when one of several conditions is met, use the bar (|) operator.
mtcars >>filter((_.cyl ==4) | (_.gear ==5))
mpg
cyl
disp
hp
drat
wt
qsec
vs
am
gear
carb
2
22.8
4
108.0
93
3.85
2.32
18.61
1
1
4
1
7
24.4
4
146.7
62
3.69
3.19
20.00
1
0
4
2
...
...
...
...
...
...
...
...
...
...
...
...
30
15.0
8
301.0
335
3.54
3.57
14.60
0
1
5
8
31
21.4
4
121.0
109
4.11
2.78
18.60
1
1
4
2
14 rows × 11 columns
The code above keeps rows where cyl is equal to 4 ORgear is equal to 5.
Be sure to explicitly put parentheses around both sides. Otherwise, python will group the operation like _.cyl == (4 | _.gear) == 5.
Dropping NA values
Filter drops rows where conditions return False or not available (NA) values. This section will cover how to tell what is considered NA, and how to drop rows of data with NA values.
What counts as NA?
Use pandas.isna() to determine whether a value is considered to be NA.