Let's say I have a numpy array a
that contains the numbers 1-10:
[1 2 3 4 5 6 7 8 9 10]
I also have a Spark dataframe to which I want to add my numpy array a
. I figure that a column of literals will do the job. This doesn't work:
df = df.withColumn("NewColumn", F.lit(a))
Unsupported literal type class java.util.ArrayList
But this works:
df = df.withColumn("NewColumn", F.lit(a[0]))
How to do it?
Example DF before:
col1 |
---|
a b c d e f g h i j |
Expected result:
col1 | NewColumn |
---|---|
a b c d e f g h i j | 1 2 3 4 5 6 7 8 9 10 |