Convert TSV to Parquet 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.
- Place input.tsv in your working folder. Use a new output filename and keep the original.
- 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 csv
import pyarrow as pa
import pyarrow.parquet as pq
with open("input.tsv", newline="", encoding="utf-8") as source:
reader = csv.DictReader(source, delimiter="\t")
if not reader.fieldnames or len(set(reader.fieldnames)) != len(reader.fieldnames):
raise ValueError("Expected unique column headers")
schema = pa.schema([(name, pa.string()) for name in reader.fieldnames])
table = pa.Table.from_pylist(list(reader), schema=schema)
pq.write_table(table, "output.parquet", compression="snappy")
print(table.schema)Limits and output
- These examples load the complete table in memory. Use small representative files first; use an explicit Arrow schema when inferred types do not match your intended values.
- The CLI/library examples use their own type mappings, which can differ from this website’s text-column conversion. Keep the source and compare nulls, identifiers, timestamps, decimals and nested values.
- The first row is the header. Every field stays text, including numeric-looking identifiers; blank fields remain empty strings.
Documentation: Apache Arrow Parquet documentation