Create Parquet data files
Persist tabular data efficiently for analytics and later reading.
Pandas · Module
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.
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.
DataFrame.to_parquet(path=None, *, engine='auto', compression='snappy', index=None, partition_cols=None, storage_options=None, filesystem=None, **kwargs)| Name | Type | Description |
|---|---|---|
path | str, path-like, file-like, or None | Destination path or None; when omitted, serialized bytes are returned. |
engine | {'auto', 'pyarrow', 'fastparquet'} | Parquet backend to use; auto, pyarrow, or fastparquet. |
compression | str or None | Compression codec, or None for no compression. |
index | bool or None | Whether to include the DataFrame index; None uses the method's default behavior. |
partition_cols | list or None | Column names used to partition the dataset. |
storage_options | dict, optional | Additional options for remote filesystem storage. |
filesystem | fsspec or pyarrow filesystem, optional | Filesystem object used for filesystem-backed destinations. |
**kwargs | dict | Additional keyword arguments passed to the selected Parquet engine. |
None when writing to a path; bytes when path is None.
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.
Persist tabular data efficiently for analytics and later reading.
Reduce storage size or tune read/write performance with a selected codec.
Organize a dataset for selective access by categorical or date-like columns.
Write to cloud or other filesystem-backed destinations.
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.
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.
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_featherpandas.DataFrame.to_orcpandas.DataFrame.to_picklepandas.read_parquet