Filters rows using the given condition 1

Filters rows using the given condition

# Filters rows using the given condition

df.filter(df.age > 3).collect()
# [Row(age=5, name='Bob')]
df.where(df.age == 2).collect()
# Row(age=2, name='Alice')]

df.filter("age > 3").collect()
# [Row(age=5, name='Bob')]
df.where("age = 2").collect()
# [Row(age=2, name='Alice')]

Here is what the above code is Doing:
1. df.filter(df.age > 3) is equivalent to df.filter(“age > 3”)
2. df.where(df.age == 2) is equivalent to df.where(“age = 2”)

Similar Posts