1

I have a dataframe df, which contains below data:

**customers**   **product**   **Val_id**
     1               A            1
     2               B            X
     3               C               
     4               D            Z

I have successfully filtered for data where column val_id is blank

df.where(col("val_id").isin(""))

But I am not able to figure out a way to filter data where column val_id is not blank, i tried something like below, but did not work for me:

df.where(col("val_id").isnotin(""))

Can anyone please help me to achieve it using Spark Scala.

3 Answers 3

3

You can use filter to get desired output:

df.filter("rule_id != ''")
Sign up to request clarification or add additional context in comments.

1 Comment

How do I collect all those rows/records from a dataframe which didn't pass this filter condition. any inbuilt methods or else?
2

Assuming Val_id is of String type, you can use this inequality operator !==:

df.where(col("Val_id") !== "").show

Conversely, you can also use === for matching the blank.

1 Comment

How do I collect all those rows/records from a dataframe which didn't pass this filter condition. any inbuilt methods or else?
0

If column type is String:

df.where(trim(col("val_id")) != "")

1 Comment

How do I collect all those rows/records from a dataframe which didn't pass this filter condition. any inbuilt methods or else?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.