I would like to remove records from a dataframe having demo_name as NULL and demo_name as empty.
demo_name is a column in that dataFrame with String datatype
I am trying the below code . I want to apply trim as there are records for demo_name with multiple spaces.
val filterDF = demoDF.filter($"demo_name".isNotNull && $"demo_name".trim != "" )
But I get error as cannot resolve symbol trim
Could someone help me to fix this issue ?
You are calling
trim
as if you are acting on aString
, but the$
function usesimplicit
conversion to convert the name of the column to theColumn
instance itself. The problem is thatColumn
doesn't have atrim
function.You need to import the library functions and apply them to your column:
Here I use the library functions
trim
andlength
--trim
to strip the spaces of course and thenlength
to verify that the result has anything in it.