Data ingestion is the critical first stage of any analytical pipeline. Loading a 10 GB CSV file into memory can crash a workstation, whereas the same dataset stored in modern Apache Parquet or Feather format loads in seconds and consumes a fraction of the RAM. In this class, we deconstruct row-based vs. columnar storage formats and benchmark them using Python.
Figure 13.1: Data Ingestion Pipeline — Raw Payloads to Parquet and Clean Columnar Feature Matrices.
| Feature | Row-Oriented (CSV, JSON, RDBMS) | Columnar (Parquet, Feather, ORC) |
|---|---|---|
| Physical Layout | Consecutive bytes on disk store entire row records. | Consecutive bytes store values of a single column together. |
| Compression Ratio | Poor (mixed data types prevent high compression). | Extreme (homogeneous types compress 5x to 10x with Snappy/ZSTD). |
| Analytical Queries | Slow (must read entire row to inspect 2 columns). | Ultra-fast (column pruning reads only queried columns). |
| Schema Integrity | Weak (CSV requires text parsing and type guessing). | Strictly typed embedded metadata. |
import time
import numpy as np
import pandas as pd
# Generate 1,000,000 rows of synthetic tabular data
np.random.seed(42)
n_rows = 1_000_000
df = pd.DataFrame({
'user_id': np.arange(n_rows),
'transaction_amount': np.random.uniform(5.0, 500.0, n_rows).round(2),
'category': np.random.choice(['Electronics', 'Apparel', 'Grocery', 'Travel'], n_rows),
'is_fraud': np.random.choice([0, 1], n_rows, p=[0.99, 0.01])
})
# 1. Write Benchmark
t0 = time.time()
df.to_csv("benchmark.csv", index=False)
csv_write_time = time.time() - t0
t0 = time.time()
df.to_parquet("benchmark.parquet", engine="pyarrow", compression="snappy")
parquet_write_time = time.time() - t0
t0 = time.time()
df.to_feather("benchmark.feather")
feather_write_time = time.time() - t0
print(f"CSV Write Time: {csv_write_time:.2f}s")
print(f"Parquet Write Time: {parquet_write_time:.2f}s (Much faster & smaller)")
print(f"Feather Write Time: {feather_write_time:.2f}s (Instantaneous zero-copy)")
# 2. Fast Column-Pruned Read with Parquet
t0 = time.time()
df_subset = pd.read_parquet("benchmark.parquet", columns=['transaction_amount', 'is_fraud'])
print(f"Column Pruned Read: {time.time() - t0:.3f}s (Read only 2 of 4 columns)")
Never store raw, intermediate, or production datasets as CSV in cloud data lakes or machine learning registries. Always default to partitioned Snappy-compressed Parquet files for cloud lakes, and Feather for high-speed local workstation caching.
Broaden your statistical analysis, Python data wrangling, and production engineering expertise:
Extract unstructured JSON payloads from third-party REST endpoints.
Leverage Apache Arrow in-memory representation for Parquet processing.
Load partitioned Parquet files directly into cloud lakehouse tables.
Query remote Parquet files directly in the browser with zero backend.