<?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 Re: 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/4706410#M9563</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/307948"&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>
    <dc:creator>nilendraFabric</dc:creator>
    <dc:date>2025-05-25T21:54:36Z</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="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/307948"&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="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/913195"&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;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screenshot 2025-05-26 100239.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1271271i655C7FE569E6DD90/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2025-05-26 100239.png" alt="Screenshot 2025-05-26 100239.png" /&gt;&lt;/span&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="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/307948"&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="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/913195"&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;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vsaisraomsft_0-1748248760154.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1271282iC2DE733515833378/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vsaisraomsft_0-1748248760154.png" alt="vsaisraomsft_0-1748248760154.png" /&gt;&lt;/span&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>

