Aller au contenu

What are the pros and cons of Parquet compared with CSV and other formats?

par Équipe NextData

0

My pipelines exchange data as CSV files and I am advised to move to Parquet. What do I actually gain, and are there cases where Parquet is the wrong choice?

Signaler

1 réponse

0

Parquet is a columnar, binary format built for analytics. CSV is row-based plain text.

Parquet CSV
Layout By column By row
File size Small: compressed and encoded per column Large
Reading a few columns Other columns are skipped Whole file is parsed
Data types Stored in the file Guessed on every read
Human-readable No Yes
Appending one row Awkward Easy

Measured on 1 million rows and 20 columns (pandas 2.3, pyarrow 25, best of 3 runs):

Parquet CSV
File size 45 MB 135 MB
Writing the file 0.4 s 6.9 s
Reading everything 55 ms 918 ms
Reading 2 columns out of 20 16 ms 553 ms

These figures depend on the machine and on the data; what matters is the order of magnitude of the gap.

Where Parquet wins:

  • analytical queries that touch a few columns out of many;
  • exchanges between Spark, DuckDB, pandas, BigQuery or Snowflake, which all read it natively;
  • filters that skip whole blocks, thanks to the min and max statistics stored for each block. In the same test, reading one day out of 694 took 4 ms from a file written in blocks of 50,000 rows, and 31 ms from a file written as a single block.

Where it is the wrong choice:

  • Row-by-row writes or frequent updates. Files are written once; use a database, or a table format such as Delta Lake or Iceberg on top of Parquet.
  • Small files exchanged with people. CSV opens anywhere.
  • Streaming one record at a time. A row-based format such as Avro fits better.
import pandas as pd

df = pd.read_csv("sales.csv")
df.to_parquet("sales.parquet", index=False)
subset = pd.read_parquet("sales.parquet", columns=["date", "amount"])

For the reviewer to check: to_parquet needs pyarrow or fastparquet installed. The figures come from a single synthetic dataset, and the CSV write time is driven largely by the date column. Native Parquet support was checked for pandas, DuckDB and Spark only, not for BigQuery or Snowflake.

Réponse rédigée par l'équipe NextData et relue par un expert.

Équipe NextData

Signaler

Votre réponse

Connectez-vous pour répondre