Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Pandas · Module

df.to_parquet

Writes a DataFrame in binary Parquet format, using an automatic or explicitly selected backend. It supports compression, index control, dataset partitioning, and filesystem-related options.

How it works

The method serializes a DataFrame as Parquet, choosing a backend automatically or through the engine argument. It can write to a path or return serialized bytes when no path is supplied, while compression, index handling, partitioning, storage options, filesystem selection, and backend-specific options are configurable.

Syntax

DataFrame.to_parquet(path=None, *, engine='auto', compression='snappy', index=None, partition_cols=None, storage_options=None, filesystem=None, **kwargs)

Parameters

NameTypeDescription
pathstr, path-like, file-like, or NoneDestination path or None; when omitted, serialized bytes are returned.
engine{'auto', 'pyarrow', 'fastparquet'}Parquet backend to use; auto, pyarrow, or fastparquet.
compressionstr or NoneCompression codec, or None for no compression.
indexbool or NoneWhether to include the DataFrame index; None uses the method's default behavior.
partition_colslist or NoneColumn names used to partition the dataset.
storage_optionsdict, optionalAdditional options for remote filesystem storage.
filesystemfsspec or pyarrow filesystem, optionalFilesystem object used for filesystem-backed destinations.
**kwargsdictAdditional keyword arguments passed to the selected Parquet engine.

Returns

None when writing to a path; bytes when path is None.

Key points

  • The method serializes the DataFrame into binary Parquet data.
  • engine selects the Parquet implementation: automatic selection, PyArrow, or fastparquet.
  • Automatic engine selection consults pandas' io.parquet.engine configuration.
  • compression chooses the codec, or None disables compression.
  • index=True stores the DataFrame index in the generated file.
  • partition_cols creates dataset partitions following the provided column order.

Common mistakes

  • partition_cols cannot be used with a non-string path.
  • Install at least one supported Parquet engine before calling the method.

Example: Write a compressed Parquet file

import pandas as pd

frame = pd.DataFrame({"group": ["a", "b"], "value": [1, 2]})
frame.to_parquet("data.parquet", engine="pyarrow", compression="zstd", index=False)

Writes the DataFrame to a compressed Parquet file without storing its index.

When to use it

Create Parquet data files

Persist tabular data efficiently for analytics and later reading.

Compress serialized output

Reduce storage size or tune read/write performance with a selected codec.

Partition a dataset

Organize a dataset for selective access by categorical or date-like columns.

Use remote storage

Write to cloud or other filesystem-backed destinations.

Interview questions

QWhat does DataFrame.to_parquet do, and what are its default engine and compression settings?

It writes the DataFrame in binary Parquet format. With engine='auto', pandas selects the configured Parquet backend, and compression defaults to Snappy.

Follow-up: How would you avoid persisting the index? Set index=False so the DataFrame index is omitted from the output.

QHow do index and compression options affect Parquet output?

The index argument controls index serialization: True includes the index, False excludes it, and None uses pandas' default index handling. The method also supports several compression codecs, including Snappy, gzip, Brotli, LZ4, and Zstandard.

Follow-up: When would partition_cols be useful? Use it to partition a dataset by selected columns, with partitions created in the supplied column order.

QWhat happens when path is None, and how can remote storage be configured?

If path is omitted, the serialized Parquet data is returned as bytes. A path can be a local or remote destination, with storage_options and filesystem available for supported storage backends.

Follow-up: What constraint applies when partitioning? partition_cols must be None when path is not a string.

  • pandas.DataFrame.to_feather
  • pandas.DataFrame.to_orc
  • pandas.DataFrame.to_pickle
  • pandas.read_parquet

Source: pandas.DataFrame.to_parquet. Checked 2026-10-15.