How would I add a list as a column to a a dataframe?

Hi, I have a list of files here, stored under the variable named “files”.

List(data/file1.csv, data/file2.csv, data/file3.csv)

and I want to add it as a column to a 3 row dataframe. I tried using this code:

  df.withColumn("col",col(files))

But I’m getting this error:

Screenshot from 2020-08-24 10-37-37

How would I fix this?

Hi,

Convert your list values to string, List(“Data/.csv”,”Data/.csv2”)

Thanks
Sri

How would I do that? Whats the syntax?

Thanks

Does not the whole thing need to be a String? Just try df.withColumn(“col”,col(files.toString))?