<?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 do I just write a CSV file to a lakehouse with a notebook? in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/How-do-I-just-write-a-CSV-file-to-a-lakehouse-with-a-notebook/m-p/4068233#M3344</link>
    <description>&lt;P&gt;Here is some more information/discussion regarding Pandas: &lt;A href="https://www.reddit.com/r/MicrosoftFabric/s/ZXrtR0nbvk" target="_blank"&gt;https://www.reddit.com/r/MicrosoftFabric/s/ZXrtR0nbvk&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 30 Jul 2024 05:10:17 GMT</pubDate>
    <dc:creator>frithjof_v</dc:creator>
    <dc:date>2024-07-30T05:10:17Z</dc:date>
    <item>
      <title>How do I just write a CSV file to a lakehouse with a notebook?</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/How-do-I-just-write-a-CSV-file-to-a-lakehouse-with-a-notebook/m-p/4064234#M3309</link>
      <description>&lt;P&gt;Greetings, all. I'm exploring Fabric notebooks and have a question. I am trying to write a simple CSV file to a lakehouse using the following code:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;spark.createDataFrame(dataframe).write.mode("overwrite").csv(LakehousePath + FilePath + FileName_NoType + '_altered')&lt;/LI-CODE&gt;&lt;P&gt;When I write this, however, I get a folder with files in it rather than a single .csv file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="arpost_0-1722013681112.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1139887i48F5CC8E52E51A9C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="arpost_0-1722013681112.png" alt="arpost_0-1722013681112.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I just save a normal csv file with the name I've chosen?&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2024 17:09:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/How-do-I-just-write-a-CSV-file-to-a-lakehouse-with-a-notebook/m-p/4064234#M3309</guid>
      <dc:creator>arpost</dc:creator>
      <dc:date>2024-07-26T17:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do I just write a CSV file to a lakehouse with a notebook?</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/How-do-I-just-write-a-CSV-file-to-a-lakehouse-with-a-notebook/m-p/4064426#M3311</link>
      <description>&lt;P&gt;One alternative is to convert to Pandas:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;# Sample data
data = [
    ("Alice", 34),
    ("Bob", 45),
    ("Catherine", 29)
]

# Define the schema
columns = ["Name", "Age"]

# Create DataFrame
df = spark.createDataFrame(data, columns)

# Convert to Pandas dataframe
df_pandas = df.toPandas()

# Write DataFrame to CSV file
df_pandas.to_csv('/lakehouse/default/Files/myFile.csv', header=True, index = False)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/fabric/data-science/read-write-pandas" target="_blank" rel="noopener"&gt;Read and write data with Pandas - Microsoft Fabric | Microsoft Learn&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Keep in mind Pandas cannot handle the same amount of data as Spark, so I guess converting to Pandas should only be done if the data is below a certain size (I have no idea what that "limit" is and what would be the consequense of breaking that limit).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Perhaps, if you are going to use pandas dataframe before saving to csv, you can might as well just use pandas dataframe everywhere in your Notebook (instead of spark dataframe). Then you don't need to convert.&lt;BR /&gt;I don't really know but perhaps that would make sense.&lt;/P&gt;&lt;P&gt;At least when you are working with small amounts of data I think you can just go with pandas.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found some other information/discussion about the topic, however I didn't find a simpler solution:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.databricks.com/t5/data-engineering/writing-spark-dataframe-as-csv-to-a-repo/td-p/60003" target="_blank" rel="noopener"&gt;writing spark dataframe as CSV to a repo - Databricks Community - 60003&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/31674530/write-single-csv-file-using-spark-csv" target="_blank" rel="noopener"&gt;scala - Write single CSV file using spark-csv - Stack Overflow&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.databricks.com/t5/data-engineering/write-in-single-csv-file/td-p/29551" target="_blank" rel="noopener"&gt;Write in Single CSV file - Databricks Community - 29551&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://engineeringfordatascience.com/posts/how_to_save_pyspark_dataframe_to_single_output_file/" target="_blank"&gt;How to Save PySpark Dataframe to a Single Output File | Engineering for Data Science&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.databricks.com/t5/data-engineering/simply-writing-a-dataframe-to-a-csv-file-non-partitioned/td-p/27818" target="_blank" rel="noopener"&gt;Solved: Simply writing a dataframe to a CSV file (non-part... - Databricks Community - 27818&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.databricks.com/t5/data-engineering/how-do-i-create-a-single-csv-file-from-multiple-partitions-in/td-p/29962" target="_blank" rel="noopener"&gt;Solved: How do I create a single CSV file from multiple pa... - Databricks Community - 29962&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/77667207/write-to-a-csv-file-using-microsoft-fabric" target="_blank" rel="noopener"&gt;python - Write to a CSV file using Microsoft Fabric - Stack Overflow&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2024 21:22:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/How-do-I-just-write-a-CSV-file-to-a-lakehouse-with-a-notebook/m-p/4064426#M3311</guid>
      <dc:creator>frithjof_v</dc:creator>
      <dc:date>2024-07-26T21:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do I just write a CSV file to a lakehouse with a notebook?</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/How-do-I-just-write-a-CSV-file-to-a-lakehouse-with-a-notebook/m-p/4065852#M3314</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/307993"&gt;@arpost&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the reply from &lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/437984"&gt;@frithjof_v&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reason you get a folder containing files instead of a single .csv file after writing the code is because Apache Spark's default behavior is to process the data in a distributed fashion and write the results to multiple partial files instead of a single file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To write CSV files to lakehouse, why not choose the no-code way of upload file, besides the alternative provided by frithjof_v&amp;nbsp;? This way is easier and faster.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vhuijieymsft_0-1722216949667.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1140447iC9BFA77926EF489C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vhuijieymsft_0-1722216949667.png" alt="vhuijieymsft_0-1722216949667.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have any other questions please feel free to contact me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Yang&lt;BR /&gt;Community Support Team&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there is any post&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;helps&lt;/EM&gt;&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Accept it as the solution&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;to help the other members find it more quickly.&lt;BR /&gt;If I misunderstand your needs or you still have problems on it, please feel free to let us know.&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Thanks a lot!&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2024 01:36:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/How-do-I-just-write-a-CSV-file-to-a-lakehouse-with-a-notebook/m-p/4065852#M3314</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-07-29T01:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I just write a CSV file to a lakehouse with a notebook?</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/How-do-I-just-write-a-CSV-file-to-a-lakehouse-with-a-notebook/m-p/4067177#M3331</link>
      <description>&lt;P&gt;@Anonymous&lt;/a&gt;, this is for an automated export process, so a manual upload of data wouldn't apply.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2024 13:43:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/How-do-I-just-write-a-CSV-file-to-a-lakehouse-with-a-notebook/m-p/4067177#M3331</guid>
      <dc:creator>arpost</dc:creator>
      <dc:date>2024-07-29T13:43:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do I just write a CSV file to a lakehouse with a notebook?</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/How-do-I-just-write-a-CSV-file-to-a-lakehouse-with-a-notebook/m-p/4067997#M3342</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/307993"&gt;@arpost&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to know why the “upload” option is used for export? I often use this option to upload a csv file and then use it, here are my test steps:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, here's my cvs file.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vhuijieymsft_0-1722305545634.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1141201iA48A2D0D1D9E8BF1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vhuijieymsft_0-1722305545634.png" alt="vhuijieymsft_0-1722305545634.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I created a lakehouse, which was just created empty.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vhuijieymsft_1-1722305545640.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1141202i3B2CFEC6AD3B81F0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vhuijieymsft_1-1722305545640.png" alt="vhuijieymsft_1-1722305545640.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used upload to upload the csv file to the lakehouse and after successful upload it shows the below image.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vhuijieymsft_2-1722305567391.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1141203iD0703DF8193EEFD6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vhuijieymsft_2-1722305567391.png" alt="vhuijieymsft_2-1722305567391.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vhuijieymsft_3-1722305567394.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1141204i0859403B6D08063D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vhuijieymsft_3-1722305567394.png" alt="vhuijieymsft_3-1722305567394.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vhuijieymsft_4-1722305579158.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1141206iC99E1CC48A00EDA7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vhuijieymsft_4-1722305579158.png" alt="vhuijieymsft_4-1722305579158.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vhuijieymsft_5-1722305579161.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1141205i057C96BA10216F9D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vhuijieymsft_5-1722305579161.png" alt="vhuijieymsft_5-1722305579161.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To use it, you can select the load to table option and then manipulate the table.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vhuijieymsft_6-1722305600835.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1141207i263BBBE7AC706625/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vhuijieymsft_6-1722305600835.png" alt="vhuijieymsft_6-1722305600835.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vhuijieymsft_7-1722305600837.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1141208iFA86C8078C1A10AF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vhuijieymsft_7-1722305600837.png" alt="vhuijieymsft_7-1722305600837.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have any other questions please feel free to contact me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Yang&lt;BR /&gt;Community Support Team&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there is any post&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;helps&lt;/EM&gt;&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Accept it as the solution&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;to help the other members find it more quickly.&lt;BR /&gt;If I misunderstand your needs or you still have problems on it, please feel free to let us know.&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Thanks a lot!&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2024 02:14:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/How-do-I-just-write-a-CSV-file-to-a-lakehouse-with-a-notebook/m-p/4067997#M3342</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-07-30T02:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do I just write a CSV file to a lakehouse with a notebook?</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/How-do-I-just-write-a-CSV-file-to-a-lakehouse-with-a-notebook/m-p/4068233#M3344</link>
      <description>&lt;P&gt;Here is some more information/discussion regarding Pandas: &lt;A href="https://www.reddit.com/r/MicrosoftFabric/s/ZXrtR0nbvk" target="_blank"&gt;https://www.reddit.com/r/MicrosoftFabric/s/ZXrtR0nbvk&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2024 05:10:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/How-do-I-just-write-a-CSV-file-to-a-lakehouse-with-a-notebook/m-p/4068233#M3344</guid>
      <dc:creator>frithjof_v</dc:creator>
      <dc:date>2024-07-30T05:10:17Z</dc:date>
    </item>
    <item>
      <title>Re: How do I just write a CSV file to a lakehouse with a notebook?</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/How-do-I-just-write-a-CSV-file-to-a-lakehouse-with-a-notebook/m-p/4069203#M3350</link>
      <description>&lt;P&gt;@Anonymous&lt;/a&gt;, when running an automated process that is generating and/or altering data, there isn't a place for a manual upload because the data being produced and exported to a file is being generated via code rather than by a human. This can then be tied into and invoked by a data pipeline as an intermediary step to do things like&lt;STRONG&gt; (1)&lt;/STRONG&gt; pull data,&lt;STRONG&gt; (2)&lt;/STRONG&gt; create a file and upload to lakehouse, and&lt;STRONG&gt; (3)&lt;/STRONG&gt; send file via email.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my scenario, I don't need to manually drop a file somewhere but instead need the process to produce the file and drop it so it can be picked up.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2024 13:10:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/How-do-I-just-write-a-CSV-file-to-a-lakehouse-with-a-notebook/m-p/4069203#M3350</guid>
      <dc:creator>arpost</dc:creator>
      <dc:date>2024-07-30T13:10:37Z</dc:date>
    </item>
  </channel>
</rss>

