Convert Parquet to CSV with Python
Run this Python script locally with Apache Arrow. The script reads your local file rather than sending it to this website.
Before you start
- Install Python 3 and create an isolated environment using the commands below.
- Work in a folder containing input.parquet. Change the filenames to your own paths and use a new output name to avoid overwriting a file.
- Save the Python code as task.py. On macOS/Linux run .venv/bin/python task.py; on Windows PowerShell run .venv\Scripts\python.exe task.py.
python3 -m venv .venv
.venv/bin/python -m pip install pyarrowpy -m venv .venv
.venv\Scripts\python.exe -m pip install pyarrowimport pyarrow.csv as csv
import pyarrow.parquet as pq
source = pq.ParquetFile("input.parquet")
options = csv.WriteOptions(include_header=True)
with csv.CSVWriter("output.csv", source.schema_arrow, write_options=options) as output:
for batch in source.iter_batches(batch_size=65536):
output.write_batch(batch)
print("Saved output.csv")Limits and output
- Writes every row with one header row and no dataframe index. CSV has no stored column types; choose an explicit null convention when another program reads it.
- Use supported flat scalar columns. Flatten or explicitly encode nested objects before CSV export. CSV can be much larger than the Parquet source.
- Review text starting with spreadsheet formula characters before opening the result in spreadsheet software. These examples do not escape spreadsheet formulas.
- Nulls are written as empty fields. Empty strings are quoted, but readers may still collapse the distinction; inspect their import settings.
- Batches reduce whole-table memory use, but unusually large values or compressed pages can still exceed available memory.
Documentation: Apache Arrow Parquet documentation