---
title: "How to Store Scraped Data as Parquet: Parquet vs CSV"
description: "Parquet is a columnar, typed, compressed file format. It keeps scraped data with its types, takes less space than CSV and is queried by date folder."
url: https://proxynet.io/blog/scraped-data-to-parquet
date: 2026-12-02
author: "Acar Diveroli"
category: "Web Scraping"
lang: en
---

# How to Store Scraped Data as Parquet: Parquet vs CSV

Parquet is a columnar, schema-based, compressed file format for tables. The type of every column is written into the file. Prices come back as numbers, and collection times come back with their time zone. CSV carries none of this and makes every reader guess the types again. This post covers how Parquet differs from CSV, writing it with pandas and pyarrow, locking the schema, splitting daily data into date folders and querying it with DuckDB.

> **Note: Short answer**
>
> Write each collection run as a new Parquet file in a date folder such as `data/date=2026-12-02/`, and lock the schema with pyarrow. Parquet keeps the types, takes far less space than CSV and can be queried directly with SQL in DuckDB.

## Parquet file structure

A Parquet file splits rows into groups and, inside each group, stores every column as a separate chunk. A footer at the end of the file holds the schema, the column types and the position where each chunk starts.

This layout has two consequences. First, a tool that only needs the `price` column never touches the others. Second, values in the same column look alike, so they compress well. Across a hundred thousand rows, the `proxy_country` column holds only a few distinct values and takes almost no space.

Parquet is a binary format. It does not open in a text editor and cannot be read by eye. To look inside a file you need a tool such as pandas, pyarrow or DuckDB.

## Parquet vs CSV

CSV is plain text and carries no type information. The reading tool guesses each column's type from its content. In our test, the stock code `00123` came back from CSV as the number `123`. The UTC timestamp came back as plain text. Read back from Parquet, the same table kept both columns in the type they were written with.

| Property | CSV | Parquet |
|---|---|---|
| Column types | ✗ Guessed on every read | ✓ Stored in the file |
| Size (our test, 112,000 rows) | 12.8 MB | 1.4 MB (snappy) |
| Reading one column | Every row is scanned | Only that column is read |
| Adding rows | Appended to the file | A new file is written |
| Reading by eye | ✓ Opens in any editor | ✗ Needs a tool |

CSV keeps two advantages: anyone can open it, and you can append rows to it. For a small one-off export it is enough. We compared CSV, JSON Lines and SQLite in [How to Save Scraped Data to CSV, JSON and SQLite](/blog/save-scraped-data-csv-json-sqlite). If you collect data every day and keep it for months, switch to Parquet.

## Writing and compression

pandas writes Parquet files through the pyarrow library. Install both into the same virtual environment:

```bash
pip install pandas pyarrow duckdb
```

The list of dicts the scraper collects goes into a DataFrame, and from there into a file:

```python
import pandas as pd

df = pd.DataFrame(rows)  # list of dicts collected by the scraper
df.to_parquet("products.parquet", index=False)  # default compression: snappy
df.to_parquet("products-zstd.parquet", index=False, compression="zstd")

back = pd.read_parquet("products.parquet", columns=["sku", "price"])
```

`index=False` stops pandas from writing its row numbers into the file. `columns` reads only the columns you ask for. The default compression is snappy, and pandas also accepts gzip, brotli, lz4 and zstd.

In our test, the same table shrank to these sizes with different compression settings:

| Compression | Size | Note |
|---|---|---|
| None | 2.2 MB | Column layout only |
| snappy | 1.4 MB | pandas and pyarrow default |
| zstd (default level) | 1.34 MB | 1.1 MB at level 3 |
| gzip | 1.07 MB | Smallest in this test |

If you have no reason to change the default, keep snappy. If disk space matters, pass `compression="zstd"` together with `compression_level=3`. These numbers come from our test data, which has repeating titles, and your ratios will differ.

## Locking the schema

A schema is the list that fixes each column's name and type in advance. Without one, pandas infers types from that day's data. If the parser one day leaves the price as text, `"1.299,90 TL"`, the `price` column in that day's file silently turns into text.

The problem shows up months later, when the folder is read. In our test we put a correctly written file and then a file written without a schema into one folder. `pd.read_parquet("data")` stopped with an `ArrowInvalid` error while reading the folder. Finding the broken file meant checking every file one by one.

The fix is to enforce the schema at write time:

```python
import pyarrow as pa

SCHEMA = pa.schema([
    ("sku", pa.string()),
    ("title", pa.string()),
    ("price", pa.float64()),
    ("currency", pa.string()),
    ("in_stock", pa.bool_()),
    ("source_url", pa.string()),
    ("http_status", pa.int16()),
    ("proxy_country", pa.string()),
    ("collected_at", pa.timestamp("us", tz="UTC")),
])

table = pa.Table.from_pandas(df, schema=SCHEMA, preserve_index=False)
```

When a row arrives with a text price, `from_pandas` stops before writing the file. The error shows up that day, on that row. Turning the price into a number is the cleaning step's job. We covered those steps in [How to Clean Scraped Data with Pandas](/blog/clean-scraped-data-with-pandas).

The timestamp unit is the second trap. pandas stores time at microsecond (`us`) precision. When we wrote millisecond (`ms`) in the schema, pyarrow refused the data loss and raised a `would lose data` error. Use `us` in the schema.

## Provenance columns

Every row should carry where and when it was collected. The price of the same product can change with the visitor's country. A price without a country cannot be interpreted later. In the schema above, four columns do this job:

- `proxy_country`: the country the request left from, as a two-letter code (`TR`, `DE`).
- `collected_at`: collection time, always in UTC.
- `source_url`: the page the data came from.
- `http_status`: the response code. It makes rows other than 200 easy to separate.

A row looks like this:

```python
from datetime import datetime, timezone

row = {
    "sku": "00123",
    "title": "Wireless headphones",
    "price": 1299.90,
    "currency": "TRY",
    "in_stock": True,
    "source_url": "https://example.com/product/00123",
    "http_status": 200,
    "proxy_country": "TR",  # exit country you chose for this run
    "collected_at": datetime.now(timezone.utc),
}
```

Take the country code from the location you chose when starting the run. We explained how country selection works in [Country and City Targeting in a Proxy](/blog/geo-targeting-proxy-explained). Fetching the same page from several countries is usually done with [Residential Proxy](https://proxynet.io/residential-proxy).

Do not write the proxy address into a column. An address like `http://user:pass@pr.proxynet.io:8000` carries the password and travels with the file. The country code and proxy type are enough.

## Date folders and appending

Once a Parquet file is written, you cannot append rows to it. pandas' `to_parquet` has no append mode. In our test, writing to the same path a second time silently replaced the earlier file. That is why every collection run writes a new file.

Putting files into date folders keeps things in order. A folder name like `date=2026-12-02/` follows the Hive partitioning convention. pandas, pyarrow and DuckDB read this name and return it as a column called `date`.

```python
import os
import uuid
from datetime import datetime, timezone
import pyarrow.parquet as pq

def save(df, root="data"):
    table = pa.Table.from_pandas(df, schema=SCHEMA, preserve_index=False)
    now = datetime.now(timezone.utc)
    folder = os.path.join(root, f"date={now:%Y-%m-%d}")
    os.makedirs(folder, exist_ok=True)
    name = f"run-{now:%H%M%S}-{uuid.uuid4().hex[:8]}.parquet"
    path = os.path.join(folder, name)
    pq.write_table(table, path, compression="zstd")
    return path
```

The random suffix in the file name stops two jobs running in the same second from overwriting each other's files. pandas' `partition_cols` parameter also builds the folders. It gives the files random names, though, which makes it harder to see which run wrote which file.

The folder date comes from UTC, and that matters for jobs near midnight. In our test, a job that ran just after midnight Türkiye time wrote its file into the previous day's folder. If you want folder dates in local time, choose that on purpose and keep it the same across all jobs.

When many small files pile up in one day, reads slow down, because each file's footer is read separately. Merging a finished day's files into one file solves this.

## Reading with pandas and DuckDB

pandas reads the whole folder in one call: `pd.read_parquet("data")`. The date in the folder name arrives as the `date` column. In our test this column came back as `category`. If you compare dates, convert it with `pd.to_datetime` first.

DuckDB is an open-source database that queries Parquet files with SQL without importing them. From Python it works like this:

```python
import duckdb

print(duckdb.sql("""
    SELECT date, proxy_country, count(*) AS rows, avg(price) AS avg_price
    FROM read_parquet('data/*/*.parquet', hive_partitioning = true)
    WHERE date >= '2026-11-30'
    GROUP BY date, proxy_country
    ORDER BY date, proxy_country
"""))
```

`hive_partitioning = true` turns the date in the folder name into a column of type `DATE`. The `WHERE` condition is applied at folder level, so files from unrelated days are never opened. On seven days of test data, the plan for a query asking for one day showed the line `Scanning Files: 1/7`. DuckDB opened only that day's file.

## Troubleshooting

Parquet errors usually come from the schema or the file layout. The symptoms we saw in testing:

- **`ArrowInvalid: Failed to parse string: '1.299,90 TL' as a scalar of type double`**: the parser left the price as text. The problem is in the scraper; the schema only catches it.
- **`Casting from timestamp[us] to timestamp[ms, tz=UTC] would lose data`**: the time unit in the schema is coarser than the data's. Use `us` in the schema.
- **`ArrowInvalid` while reading a folder**: the folder holds an old file written without a schema. Check each file's `price` type with `pq.read_schema(path)`.
- **Stock codes lost the zeros at their start**: the data passed through CSV at some point. Keep the whole chain in Parquet.
- **`PermissionError: [WinError 32]` on Windows**: an object reading the file is still open. Do not delete or move the file before reading is done.

## How we tested

We ran the tests on December 2, 2026 on Windows 11 with Python 3.13.17, pandas 3.1.2, pyarrow 26.0.1 and DuckDB 2.0.1. We ran the post's code blocks in order in a single script. We saw the type loss by writing a two-row table as CSV and as Parquet and reading both back.

For the size measurements we generated a synthetic dataset: 2,000 products, two countries, seven days and four runs a day, 112,000 rows and nine columns in total. Product titles were drawn from a pool of 20 words. Because of that, the data compresses better than real pages. We read file sizes from the file system after writing had finished.

## The bottom line

Write each run to a new file in a date folder, enforce the schema with pyarrow, and store country and time as columns. Above all, do not write without a schema. A single broken day stops the whole folder from being read months later. For collection jobs that send each request from a different IP, see [Rotating Proxy](https://proxynet.io/rotating-proxy).

## Sources

- [Apache Parquet Documentation, Overview](https://parquet.apache.org/docs/overview/): parquet.apache.org
- [pandas.DataFrame.to_parquet](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_parquet.html): pandas.pydata.org
- [pyarrow.parquet.write_table](https://arrow.apache.org/docs/python/generated/pyarrow.parquet.write_table.html): arrow.apache.org
- [DuckDB, Reading and Writing Parquet Files](https://duckdb.org/docs/2.0/data/parquet/overview): duckdb.org

## Frequently asked questions

### How do I look inside a Parquet file?

With pandas or DuckDB. `pd.read_parquet("file.parquet").head()` shows the first rows. To see only the schema, `pq.read_schema("file.parquet")` is enough and does not read the data. In DuckDB you write the file name directly as a table: `SELECT * FROM 'file.parquet' LIMIT 10`. Parquet is a binary format, so a text editor shows nothing meaningful.

### Is Parquet faster to read than CSV?

For most analysis, yes. The gap is largest for queries that read a few columns, because Parquet reads only the requested columns from disk. With CSV, every row is scanned end to end and the types are inferred again. With very small files you will not notice a difference. To decide for your own data, time the same query in both formats.

### Can I append rows to an existing Parquet file?

No. You cannot append rows to a file that has been written and closed. New rows go into a new file in the same folder. pyarrow's `ParquetWriter` class can add new row groups while the file stays open. That suits a single long-running job. Once the file is closed, changing it means reading it and writing it again.

### Should I choose snappy or zstd?

The default, snappy, is enough for most work. It is fast and widely supported by tools that read Parquet. If disk space or storage cost matters, choose zstd. In our test, zstd at level 3 made the file about a fifth smaller than snappy. You set the level with the `compression_level` parameter. Compression is chosen per file and can be mixed within a folder.

### One file per day or one file per run?

Write one file per run. If a run is cut off halfway, only its own file is missing and earlier data is unaffected. A few files from a few runs a day are not a problem. Once the file count reaches the hundreds, reads slow down. Then merge the finished day's files into one file and delete the old ones.

### Should I store the proxy address in the data?

No. A proxy address carries the username and password. When the data file is shared or backed up, the password travels with it. Write only what you need to interpret the row: the two-letter code of the exit country, the proxy type if needed, and the UTC collection time. Keep credentials in an environment variable or a secrets store.
