I am working in Pyspark environment in Databricks and have a pyspark data frame which I will call as df.
I need to push this spark dataframe into csv file, I am unable to do so. Though there is no error popping up but the dataframe doesn’t get copied into the csv. Below is the generic code
path = “ “ #CSV File Location
header = “This is the header of the file"
With open(path,”a”) as f:
f.write(header+”\n”)
df.write.csv(path=path,format=“csv”,mode=“append”)
f.close
Only the header gets reflected in the file and not the dataframe