val someDF = Seq(
(8, "bat"),
(64, "mouse"),
(-27, "horse"),
(10, null),
(11, "")
).toDF("number", "word")
Using this above data frame I'm trying to filter out null and empty word column values.
Trail - 1
someDF.filter(col("word") =!= "" || col("word").isNotNull).show(false)
+------+-----+
|number|word |
+------+-----+
|8 |bat |
|64 |mouse|
|-27 |horse|
|11 | |
+------+-----+
I have used OR condition but still, it is not removing the empty string word column values.
Trail - 2
someDF.filter(col("word") =!= "").filter(col("word").isNotNull).show(false)
+------+-----+
|number|word |
+------+-----+
|8 |bat |
|64 |mouse|
|-27 |horse|
+------+-----+
In trail - 2 I have used the chain filter then it removed both null and empty values from the data frame.
Trail - 3
someDF.filter(col("word") =!= "" && col("word").isNotNull).show(false)
+------+-----+
|number|word |
+------+-----+
|8 |bat |
|64 |mouse|
|-27 |horse|
+------+-----+
In trail -3 I have used AND operation then it removed the null/empty values.
Can anyone please explain to me why with OR operation it's not working? Is something wrong in my code?