Menu
CoddyTech

Write Parquet Data

Part of the Fundamentals section of Coddy's PySpark journey. Lesson 17 of 18.

Parquet stores tabular data with its schema, including column types. Write a DataFrame using df.write.parquet(path) and load it with spark.read.parquet(path). Spark normally writes a directory of part files, not one file with the exact path as its filename.

df.write.mode("overwrite").parquet(path)
loaded = spark.read.parquet(path)

The default write mode fails if the destination already exists. overwrite replaces its contents; append adds records. Choose a mode deliberately. These exercises use temporary workspace paths, so overwriting affects only that exercise’s data.

challenge icon

Challenge

Easy

Complete save_data(df, path). Write the supplied DataFrame as Parquet at a new destination. The checker reloads the saved data. Preserve both columns and every row. No return value is required.

The checker supplies the path; use the path argument. Schema: id int, name string. The session and F are available. Do not print; the checker reads and displays the result rows.

Try it yourself

def save_data(df, path):
    pass
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals

Practice on your own: Online Python compiler