Skip to content
Home » pySpark » How to Save PySpark DataFrame to Microsoft Fabric Lakehouse | Files & Tables

How to Save PySpark DataFrame to Microsoft Fabric Lakehouse | Files & Tables

5/5 - (1 vote)

In this tutorial, you will learn how to save a PySpark DataFrame to a Microsoft Fabric Lakehouse. We will explore two common approaches for storing DataFrame data in a Lakehouse.

What You Will Learn

We will save the same PySpark DataFrame in the following two ways:

  • Save as a file: Store the DataFrame as a file in the Files section of the Microsoft Fabric Lakehouse.
  • Save as a table: Store the DataFrame as a table in the Tables section of the Microsoft Fabric Lakehouse.

This practical example will help you understand how PySpark DataFrames can be written to different storage locations in a Microsoft Fabric Lakehouse.

# Save DataFrame as CSV

df.write \
    .mode("overwrite") \
    .format("csv") \
    .option("header", "true") \
    .save("Files/SampleDataCSV")




# Save DataFrame as Parquet

df.write \
    .mode("overwrite") \
    .format("parquet") \
    .save("Files/SampleDataParquet")

# Save DataFrame as Delta Table

df.write \
    .mode("overwrite") \
    .format("delta") \
    .saveAsTable("SampleSales")

Refer to the video below for a practical demonstration-

Loading

Leave a Reply

Discover more from Power BI Docs

Subscribe now to keep reading and get access to the full archive.

Continue reading