Skip to content Skip to sidebar Skip to footer

Pyspark Dataframe - How To Pass String Variable To Df.where() Condition

I am not sure is this possible in pyspark. I believe it should be just that i am not winning here :(. Requirement: Bring any records whose FNAME and LNAME is null or 0 Expected res

Solution 1:

If you want to use a string condition you can use an SQL filter clause:

condition = ' AND '.join(['('+ col + ' IS NULL OR ' + col + ' = 0)' for col in df.columns])
df.filter(condition)

Post a Comment for "Pyspark Dataframe - How To Pass String Variable To Df.where() Condition"