cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Filtering rows that does not contain a string

KutayKoralturk
New Contributor

search = search.filter(!F.col("Name").contains("ABC"))

search = search.filter(F.not(F.col("Name").contains("ABC"))

Both methods fail due to syntax error could you please help me filter rows that does not contain a certain string in pyspark.

^ SyntaxError: invalid syntax

2 REPLIES 2

User16857282152
Contributor

Here is a complete example

values = [("K1","true","false"),("K2","true","false")] 
columns = ['Key', 'V1', 'V2']
df = spark.createDataFrame(values, columns)
display(df)

FILTER

df2 = df.filter(df.column2 != "delete")
display(df2)

OOps

Copy and past error, the First code block should be,

values = [("save","save"),("save", "delete")] 
columns = ['column1','column2']
df = spark.createDataFrame(values, columns)
display(df)

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group