ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

Pandas Tutorial• 7 min read

Reading & Writing Data: CSV, Excel, Parquet & SQL

Fast I/O with read_csv, read_parquet, memory optimization, and chunking

Pandas provides flexible I/O functions to load and export datasets from CSV, Excel, JSON, Parquet, and relational databases.

Modern Storage Formats: CSV vs Parquet

CSV (pd.read_csv, df.to_csv): Human-readable plain text, but slow to parse and does not preserve data types (like datetimes or categories).

Parquet (pd.read_parquet, df.to_parquet): A columnar binary storage format that compresses data up to 80% smaller and loads 10x to 50x faster while preserving exact schema datatypes.

Chunking: When loading multi-gigabyte CSV files that exceed RAM, pass chunksize=100_000 to read_csv() to iterate over data streamingly.

Optimized CSV and Parquet Loading
import pandas as pd

# Load CSV specifying explicit data types to save 60% memory
# df = pd.read_csv("large_sales.csv", dtype={"user_id": "int32", "country": "category"})

# Export to compressed Parquet format
# df.to_parquet("sales_optimized.parquet", compression="snappy")

# Read Parquet preserving native types
# df_fast = pd.read_parquet("sales_optimized.parquet")
Specifying dtypes and migrating to Parquet saves memory and speeds up execution.
ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

Why is Parquet preferred over CSV for large production data pipelines in Pandas?