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-
![]()