<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic how to write a spark dataframe into csv file without losing column headers in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/how-to-write-a-spark-dataframe-into-csv-file-without-losing/m-p/4706394#M9562</link>
    <description>&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;***&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;yearlySales = df.select(year(col("OrderDate")).alias("Year")).groupBy("Year").count().orderBy("Year")

yearlySales.write.mode("overwrite").format("csv").save("Files/yearlySales.csv")&lt;/LI-CODE&gt;&lt;P&gt;***&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 25 May 2025 19:40:57 GMT</pubDate>
    <dc:creator>Jeanxyz</dc:creator>
    <dc:date>2025-05-25T19:40:57Z</dc:date>
    <item>
      <title>how to write a spark dataframe into csv file without losing column headers</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/how-to-write-a-spark-dataframe-into-csv-file-without-losing/m-p/4706394#M9562</link>
      <description>&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;***&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;yearlySales = df.select(year(col("OrderDate")).alias("Year")).groupBy("Year").count().orderBy("Year")

yearlySales.write.mode("overwrite").format("csv").save("Files/yearlySales.csv")&lt;/LI-CODE&gt;&lt;P&gt;***&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 May 2025 19:40:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/how-to-write-a-spark-dataframe-into-csv-file-without-losing/m-p/4706394#M9562</guid>
      <dc:creator>Jeanxyz</dc:creator>
      <dc:date>2025-05-25T19:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a spark dataframe into csv file without losing column headers</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/how-to-write-a-spark-dataframe-into-csv-file-without-losing/m-p/4706410#M9563</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="307948" data-lia-user-login="Jeanxyz" class="lia-mention lia-mention-user"&gt;Jeanxyz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;yearlySales.write.mode("overwrite").option("header", True).format("csv").save("Files/yearlySales.csv")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;option(“header”, True): Ensures that the column headers are written as the first row in the CSV output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 May 2025 21:54:36 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/how-to-write-a-spark-dataframe-into-csv-file-without-losing/m-p/4706410#M9563</guid>
      <dc:creator>nilendraFabric</dc:creator>
      <dc:date>2025-05-25T21:54:36Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a spark dataframe into csv file without losing column headers</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/how-to-write-a-spark-dataframe-into-csv-file-without-losing/m-p/4706996#M9590</link>
      <description>&lt;P&gt;Thanks a lot, &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="913195" data-lia-user-login="nilendraFabric" class="lia-mention lia-mention-user"&gt;nilendraFabric&lt;/a&gt;&amp;nbsp;. This works. I have yet another question. What's the best Spark tutorial online? I searched on&amp;nbsp;&lt;A href="https://spark.apache.org/," target="_blank"&gt;https://spark.apache.org/,&lt;/A&gt;&amp;nbsp;but the documentation about dataframe write method seems quite limited.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 May 2025 08:04:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/how-to-write-a-spark-dataframe-into-csv-file-without-losing/m-p/4706996#M9590</guid>
      <dc:creator>Jeanxyz</dc:creator>
      <dc:date>2025-05-26T08:04:26Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a spark dataframe into csv file without losing column headers</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/how-to-write-a-spark-dataframe-into-csv-file-without-losing/m-p/4707071#M9592</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="307948" data-lia-user-login="Jeanxyz" class="lia-mention lia-mention-user"&gt;Jeanxyz&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;Thank you for reaching out to the Microsoft Fabric Forum Community.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check the solution provided by &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="913195" data-lia-user-login="nilendraFabric" class="lia-mention lia-mention-user"&gt;nilendraFabric&lt;/a&gt;, adding.option("header", True) to your .write() operation will ensure the column headers are written as the first row in your CSV file.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also refer to the official Apache Spark documentation for more context on the header option:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://downloads.apache.org/spark/docs/3.3.2/sql-data-sources-csv.html" target="_blank"&gt;CSV Files - Spark 3.3.2 Documentation&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this post&amp;nbsp;helps, then please give us ‘Kudos’ and consider&amp;nbsp;Accept it as a solution&amp;nbsp;to help the other members find it more quickly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 May 2025 08:41:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/how-to-write-a-spark-dataframe-into-csv-file-without-losing/m-p/4707071#M9592</guid>
      <dc:creator>v-saisrao-msft</dc:creator>
      <dc:date>2025-05-26T08:41:11Z</dc:date>
    </item>
  </channel>
</rss>

