df=spark.sql("select key, name, subjects from table")
df in from above select statement :
key name subjects 12 x,y,z 1,2,3 20 a,b 8,7