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
🌐
Apache
spark.apache.org › docs › latest › api › python › reference › pyspark.sql › api › pyspark.sql.functions.contains.html
pyspark.sql.functions.contains — PySpark 4.2.0 documentation
pyspark.sql.functions.contains(left, right)[source]# Returns a boolean. The value is True if right is found inside left. Returns NULL if either input expression is NULL. Otherwise, returns False. Both left or right must be of STRING or BINARY type. New in version 3.5.0.
🌐
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
>>> df = spark.createDataFrame( ... [(2, "Alice"), (5, "Bob")], ["age", "name"]) >>> df.filter(df.name.contains('o')).collect() [Row(age=5, name='Bob')]
🌐
Databricks
api-docs.databricks.com › python › pyspark › latest › pyspark.sql › api › pyspark.sql.Column.contains.html
pyspark.sql.Column.contains — PySpark master documentation
Contains the other element. Returns a boolean Column based on a string match · string in line. A value as a literal or a Column
🌐
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.functions.array_contains.html
pyspark.sql.functions.array_contains — PySpark 4.2.0 documentation
Example 1: Basic usage of array_contains function. >>> from pyspark.sql import functions as sf >>> df = spark.createDataFrame([(["a", "b", "c"],), ([],)], ['data']) >>> df.select(sf.array_contains(df.data, "a")).show() +-----------------------+ |array_contains(data, a)| +-----------------------+ | true| | false| +-----------------------+ Example 2: Usage of array_contains function with a column.
🌐
Databricks
docs.databricks.com › pyspark reference › functions › contains
contains | Databricks on AWS
June 4, 2026 - contains function in PySpark: Returns a boolean. The value is True if right is found inside left. Returns NULL if either input expression is NULL. Otherwise, returns False.
Find elsewhere
🌐
Microsoft Learn
learn.microsoft.com › en-us › azure › databricks › pyspark › reference › functions › contains
contains - Azure Databricks | Microsoft Learn
June 4, 2026 - contains function in PySpark: Returns a boolean. The value is True if right is found inside left. Returns NULL if either input expression is NULL. Otherwise, returns False.
🌐
Statology
statology.org › home › pyspark: how to filter using “contains”
PySpark: How to Filter Using "Contains"
October 12, 2023 - #filter DataFrame where team column contains 'avs' df.filter(df.team.contains('avs')).show() The following example shows how to use this syntax in practice. Suppose we have the following PySpark DataFrame that contains information about points scored by various basketball players:
🌐
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.
🌐
Databricks
docs.databricks.com › pyspark reference › column › contains
contains (Column) | Databricks on AWS
June 4, 2026 - Column.contains method in PySpark: Check if a string column contains a substring.
🌐
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.
🌐
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
🌐
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` ...