Edit a Parquet value 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 as pa
import pyarrow.parquet as pq
table = pq.read_table("input.parquet")
print(table.schema)
column_name = table.column_names[0]
values = table.column(column_name).to_pylist()
if not values:
raise ValueError("The file has no rows to edit")
# Replace None with a value compatible with the printed column type.
values[0] = None
index = table.schema.get_field_index(column_name)
replacement = pa.array(values, type=table.schema.field(index).type)
table = table.set_column(index, table.schema.field(index), replacement)
pq.write_table(table, "edited.parquet", compression="snappy")
print(pq.read_table("edited.parquet").slice(0, 10).to_pylist())Limits and output
- This example sets the first cell to null and writes edited.parquet. Use a nullable column and replace the example edit with your intended value.
- It loads the complete table into memory and rewrites the file. It does not preserve byte layout, row-group boundaries, statistics or original compression. Check your schema and saved values.
Documentation: Apache Arrow Parquet documentation