Skip to main content

How to Save a pandas DataFrame to a Parquet File

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

Parquet is a file format for tables that stores each column's type with the data and compresses it well, which makes it a common choice for data that other tools read. pandas writes it with to_parquet. This guide saves a small table and reads it back, with real output from pandas 3.1.1 and pyarrow 26.0.1.

Syntax​

Syntax
<dataframe>.to_parquet("<file>.parquet")
<dataframe> = pd.read_parquet("<file>.parquet")
PartWhat it means
to_parquet("<file>.parquet")Writes the DataFrame, with its column types, to the file
pd.read_parquet(...)Reads it back into a DataFrame

The pandas reference: "Write a DataFrame to the binary parquet format. This function writes the dataframe as a parquet file."

Prerequisites​

  • pandas and pyarrow in your project, for example with uv add pandas pyarrow. pandas needs pyarrow (or fastparquet) to write Parquet. This guide uses pandas 3.1.1 and pyarrow 26.0.1 on Python 3.15.2.

Step 1: Write the Script​

save_parquet.py
import pandas as pd

cities = pd.DataFrame({"city": ["Paris", "Rome"], "visitors": [120, 95]})
cities.to_parquet("cities.parquet")

print(pd.read_parquet("cities.parquet"))

The save_parquet.py script in a macOS-style code window: a cities DataFrame, cities.to_parquet("cities.parquet"), and a print of pd.read_parquet("cities.parquet").

Step 2: Run It​

Terminal
uv run python save_parquet.py
Output
city visitors
0 Paris 120
1 Rome 95

The script's output in a terminal: the table read back from cities.parquet, Paris 120 and Rome 95.

The script wrote cities.parquet next to itself, and the table came back from it unchanged.

Common Mistakes​

MistakeWhat happensDo this instead
No pyarrow in the projectImportError: Unable to find a usable engine; tried using: 'pyarrow', 'fastparquet'.uv add pyarrow
Using CSV where the types matterA CSV keeps only text: read back, it also gained an Unnamed: 0 column from the saved indexParquet kept city as str and visitors as int64, with no extra column

Troubleshooting​

SymptomLikely causeFix
ImportError: Unable to find a usable engineNeither pyarrow nor fastparquet is installedAdd pyarrow to the project

FAQ​

Can I open a Parquet file in a text editor?​

No. It's a binary format; read it with pandas, or with another tool that supports Parquet.

Does to_parquet save the index?​

By default, yes, compactly. The reference, for the default index=None: "the RangeIndex will be stored as a range in the metadata so it doesn't require much space and is faster." That's why read_parquet gave back the same table without an extra column.

Conclusion​

cities.to_parquet("cities.parquet") saved the table and pd.read_parquet read it back with its types, as long as pyarrow is in the project.

Additional Resources​