I have a list of columns like this check_columns = ["col1", "col2"] and I want to remove null value from check_columns list with this rule:
df = df.filter(
F.col(check_columns[0]).isNotNull() & (F.size(check_columns[0]) > 0) |
F.col(check_columns[1]).isNotNull() & (F.size(check_columns[1]) > 0)
)
If my list has more elements like check_columns = ["col1", "col2", "col3", "col4].
How can I create a filter without creating new rows? One thing I find difficult is that it must be OR between each filter condition.
I have tried this code but it does not work:
df = df.filter(
(
' | '.join([F.col(c).isNotNull() & (F.size(c) > 0) for c in check_columns])
)
)