VOOZH about

URL: https://www.geeksforgeeks.org/python/pyspark-dataframe-where-filter/

⇱ PySpark DataFrame - Where Filter - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

PySpark DataFrame - Where Filter

Last Updated : 28 Mar, 2022

In this article, we are going to see where filter in PySpark Dataframe. Where() is a method used to filter the rows from DataFrame based on the given condition. The where() method is an alias for the filter() method. Both these methods operate exactly the same. We can also apply single and multiple conditions on DataFrame columns using the where() method.

Syntax: DataFrame.where(condition)

Example 1:

The following example is to see how to apply a single condition on Dataframe using the where() method.

Output:

👁 Image

Example 2:

The following example is to understand how to apply multiple conditions on Dataframe using the where() method.

Output:

👁 Image

Example 3:

The following example is to know how to filter Dataframe using the where() method with Column condition. We will use where() methods with specific conditions.

Output:

👁 Image

Example 4:

The following example is to know how to use where() method with SQL Expression.

 Output:

👁 Image

Comment