Forum Discussion
Jeanxyz
1 year agoPower Participant
how to write a spark dataframe into csv file without losing column headers
I have created a notebook and a spark data frame, when I write the data frame into a csv file, the column header is not written into csv. Is that normal? *** yearlySales = df.select(year(col("Orde...
- 1 year ago
Hi Jeanxyz
yearlySales.write.mode("overwrite").option("header", True).format("csv").save("Files/yearlySales.csv")
option(“header”, True): Ensures that the column headers are written as the first row in the CSV output.
Jeanxyz
1 year agoPower Participant
Thanks a lot, nilendraFabric . This works. I have yet another question. What's the best Spark tutorial online? I searched on https://spark.apache.org/, but the documentation about dataframe write method seems quite limited.