I have a list with all values distinct in a column and I need to replace all values that IS NOT IN this list with 1
I've tried this
uniq = X_train3.select('street').distinct().collect()
X_test3 = X_test3.withColumn('street', F.when(array_contains('street', uniq), 1))
and i also tried this:
uniq = X_train3.select('street').distinct().collect()
X_test3 = X_test3.withColumn('street', F.when(~col('street').isin(uniq), 1))
both result in this error: java.lang.RuntimeException: Unsupported literal type class java.util.ArrayList [[1.0]]
This is what I did in python and works:
uniq = X_train3[cl].unique()
uniq = uniq.tolist()
X_test3['street'] = X_test3['street'].map(lambda x: 1 if x not in uniq else x)]