Spark 2.2 onwards

df.filter(df.location.contains('google.com'))

Spark 2.2 documentation link


Spark 2.1 and before

You can use plain SQL in filter

df.filter("location like '%google.com%'")

or with DataFrame column methods

df.filter(df.location.like('%google.com%'))

Spark 2.1 documentation link

Answer from mrsrinivas on Stack Overflow
🌐
Spark By {Examples}
sparkbyexamples.com › home › pyspark › pyspark filter using contains() examples
PySpark Filter using contains() Examples - Spark By {Examples}
May 6, 2026 - PySpark SQL contains() function is used to match a column value contains in a literal string (matches on part of the string), this is mostly used to
🌐
Apache
spark.apache.org › docs › latest › api › python › reference › pyspark.sql › api › pyspark.sql.Column.contains.html
pyspark.sql.Column.contains — PySpark 4.1.2 documentation
Contains the other element. Returns a boolean Column based on a string match. Changed in version 3.4.0: Supports Spark Connect. Parameters · other · string in line. A value as a literal or a Column. Examples · >>> df = spark.createDataFrame( ... [(2, "Alice"), (5, "Bob")], ["age", "name"]) ...
🌐
Statology
statology.org › home › pyspark: how to filter using “contains”
PySpark: How to Filter Using "Contains"
October 12, 2023 - We can use the following syntax to filter the DataFrame to only contain rows where the team column contains “avs” somewhere in the string:
🌐
Statology
statology.org › home › pyspark: filter for rows that contain one of multiple values
PySpark: Filter for Rows that Contain One of Multiple Values
October 12, 2023 - We can use the following syntax to filter the DataFrame to only contain rows where the team column contains “ets” or “urs” somewhere in the string:
🌐
Spark By {Examples}
sparkbyexamples.com › home › apache spark › spark filter using contains() examples
Spark Filter Using contains() Examples - Spark By {Examples}
May 6, 2026 - In Spark & PySpark, contains() function is used to match a column value contains in a literal string (matches on part of the string), this is mostly
Find elsewhere
🌐
Arab Psychology
scales.arabpsychology.com › home › how to filter a pyspark dataframe using the contains function
How To Filter A PySpark DataFrame Using The Contains Function
February 10, 2026 - In this code snippet, df.team references a specific column within the DataFrame named df. The contains(‘avs’) method is then invoked on that column, which generates a Boolean column expression.
🌐
Sqlandhadoop
sqlandhadoop.com › pyspark-filter-25-examples-to-teach-you-everything
PySpark Filter – 25 examples to teach you everything – SQL & Hadoop
PySpark contains filter condition is similar to LIKE where you check if the column value contains any give value in it or not. Basically you check if the sub-string exists in the string or not.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pyspark › pyspark where() & filter() for efficient data filtering
PySpark where() & filter() for efficient data filtering - Spark By {Examples}
May 6, 2026 - In this PySpark article, you will learn how to apply a filter on DataFrame columns of string, arrays, and struct types by using single and multiple
🌐
Medium
medium.com › @pubududewagama › exploring-pyspark-filter-functions-in-data-engineering-f5beebc305f3
Exploring PySpark Filter Functions in Data Engineering | by Pubudu Dewagama | Medium
January 9, 2024 - 5. Filter Based on Starts With, Ends With, Contains: Highlight the efficiency of PySpark filters in handling string manipulations, specifically focusing on starting, ending, or containing specific substrings.
🌐
MungingData
mungingdata.com › pyspark › filter-array
Filtering PySpark Arrays and DataFrame Array Columns - MungingData
The pyspark.sql.DataFrame#filter method and the pyspark.sql.functions#filter function share the same name, but have different functionality. One removes elements from an array and the other removes rows from a DataFrame. It's important to understand both. The rest of this post provides clear examples. Suppose you have the following DataFrame with a some_arr column that contains numbers.
🌐
Spark Code Hub
sparkcodehub.com › pyspark › dataframe › filter-rows-array-contains
How to Filter Rows with array_contains in an Array Column in a PySpark DataFrame: The Ultimate Guide
array_contains() function checks if a specified value is present in an array column, returning a boolean that can be used with · filter() to select matching rows. This is ideal for scenarios where you need to query complex data, like lists of skills, tags, or product IDs, without unpacking ...
🌐
HKR Trainings
hkrtrainings.com › home › sample resumes › big data analytics › pyspark filter
➤ PySpark Filter | A Step by Step Guide on PySpark Filter
June 12, 2024 - The first syntax can be used to ... array contains() from Pyspark SQL functions, which checks if a value exists in an array and returns true if it does, otherwise false....
🌐
Arab Psychology
scales.arabpsychology.com › psychological scales › pyspark: filter using contains”
PySpark: Filter Using Contains”
November 17, 2025 - The PySpark framework uses the `filter()` method to select rows based on a conditional expression applied across one or more columns. When employing string matching, the condition is created by selecting the target column, applying the `contains` ...
🌐
Dbmstutorials
dbmstutorials.com › pyspark › spark-dataframe-filters.html
PySpark: Dataframe Filters
This tutorial will explain how filters can be used on dataframes in Pyspark. where() function is an alias for filter() function. Following topics will be covered on this page: Basic filters · Filter using IN clause · Filter using not IN clause · Filter using List · Filter Null Values · Filter not Null Values · Filter using LIKE operator · Filter using not LIKE operator · Filter using Contains ·
🌐
Skytowner
skytowner.com › explore › pyspark_column_contains_method
PySpark Column | contains method with Examples
PySpark Column's contains(~) method returns a Column object of booleans where True corresponds to column values that contain the specified substring.
🌐
Medium
medium.com › @uzzaman.ahmed › how-to-use-where-and-filter-in-a-dataframe-with-examples-bc2a9544ae3f
How to use `where()` and `filter()` in a DataFrame with Examples | by Ahmed Uz Zaman | Medium
January 31, 2023 - You can also use the filter() function instead of the where() function, which works the same way. from pyspark.sql.functions import array_contains filtered_df = df.filter(array_contains(col("colors"), "red"))