TL;DR: This project tests how fast different Python libraries process large datasets. Spoiler alert: Polars wins by a lot!
Imagine you have a huge CSV file with millions of rows (like sales data, user logs, etc.). This project tests 5 different Python libraries to see which one processes the data fastest:
This project uses REAL production data from the Japanese Trade Statistics dataset (1988-2020) for benchmarking:
- Source: 100 million data (csv) on Kaggle by TadashiNagao
- Original Data: Japan Customs
- License: CC BY-SA 4.0
- Original Size: 4.23 GB, 113.6 million rows (custom_1988_2020.csv)
- Content: Real Japanese import/export trade records from 1988-2020 with anonymized column names for universal benchmarking
Why Real Data Matters: Unlike synthetic benchmarks, this uses actual production data with real-world patterns, distributions, and characteristics - making the performance results much more credible and applicable to real scenarios.
Column mapping (anonymized for general benchmarking):
year_monthβ ym (year + month)category1β exp_imp (export/import indicator)category2β hs9 (Harmonized System product code)category3β Customs (customs point code)codeβ Country (country code)flagβ additional classifiervalue1β Q1/Q2 (quantity)value2β Value (in thousands of yen)
The dataset has been processed with generalized column names to focus on data processing performance rather than domain-specific analysis.
- Pandas πΌ - The most popular one everyone knows
- Polars β‘ - The new super-fast kid on the block
- PyArrow πΉ - Good for pure numbers
- Dask πͺοΈ - For when your data is too big for memory
- PySpark β‘ - For truly massive datasets
We tested all libraries on different dataset sizes. Here's what we found:
Updated with real production data from custom_1988_2020.csv (1988-2020 trade statistics):
| Dataset Size | Winner | 2nd Place | Pandas Time | Winner Time | Speed Boost |
|---|---|---|---|---|---|
| 1M rows | Polars | PyArrow | 1.51s | 0.42s | 3.6x faster |
| 5M rows | Polars | PyArrow | 7.69s | 1.84s | 4.2x faster |
| 10M rows | Polars | PyArrow | 16.95s | 2.87s | 5.9x faster |
| 50M rows | Polars | PyArrow | 122.75s | 22.95s | 5.3x faster |
Note: All benchmarks use real-world data extracted from the original 113.6M row dataset, not synthetic data.
Polars uses 50-60% less memory than Pandas!
- 10M rows: Pandas = 1.46GB, Polars = 0.55GB
- 50M rows: Pandas = 7.22GB, Polars = 2.66GB
- β You want the fastest performance (almost always)
- β You care about memory usage
- β You have any dataset from 100K to 50M+ rows
- β You want modern, clean syntax
- β You're working with small datasets (< 1M rows)
- β Your team already knows Pandas well
- β You need specific Pandas-only features
β οΈ Warning: Gets slow and memory-hungry with large data
- β You have pure numerical data (no text processing)
- β You need to work with Apache ecosystem tools
- β You want good performance with numerical operations
- β You have truly massive datasets (100M+ rows)
- β You have a cluster of computers
- β You need distributed processing
- β Your data doesn't fit in memory
- β You want to scale existing Pandas code
β οΈ Note: Usually slower than other options
# 1. Clone this project
git clone <your-repo-url>
cd study-stuff
# 2. Create a virtual environment (recommended)
python -m venv venv
# 3. Activate it
# On Windows:
venv\Scripts\activate
# On Mac/Linux:
source venv/bin/activate
# 4. Install required packages
pip install -r requirements.txt# First time only: Extract real-world data subsets from the original dataset
cd scripts/data_generation
python extract_real_world_datasets.py
# This creates benchmark datasets (1M, 5M, 10M, 50M, 100M rows) from custom_1988_2020.csv# Navigate to the benchmark folder
cd ../benchmarks/dataset_specific
# Run tests on different dataset sizes (now using REAL data!)
python benchmark_1m_simple.py # Takes ~30 seconds
python benchmark_5m_simple.py # Takes ~2 minutes
python benchmark_10m_simple.py # Takes ~3 minutes
python benchmark_50m_simple.py # Takes ~8 minutes
python benchmark_100m_simple.py # Takes ~15 minutes (for big data comparison)# Go back to main folder
cd ../../..
# Look at the results
ls results/
# You'll see files like:
# performance_metrics_polars_10m.json
# performance_metrics_pandas_10m.json
# etc.study-stuff/
βββ scripts/benchmarks/dataset_specific/ β The benchmark tests are here
βββ results/ β Results appear here as JSON files
βββ data/ β CSV datasets are stored here
βββ charts/ β Generated charts go here
βββ README.md β You are here!
Each test creates a JSON file with timing results. Here's what the numbers mean:
{
"total_operation_time_seconds": 2.87, β Total time to process everything
"loading_time_seconds": 0.503, β Time to load the CSV file
"cleaning_time_seconds": 0.005, β Time to clean missing data
"aggregation_time_seconds": 0.780, β Time to group and calculate averages
"sorting_time_seconds": 1.008, β Time to sort the data
"filtering_time_seconds": 0.057, β Time to filter rows
"correlation_time_seconds": 0.515, β Time to calculate correlations
"memory_size_gb": 0.549, β Memory used (in GB)
"row_count": 10000000 β Number of rows processed
}Lower numbers = faster performance! πββοΈπ¨
cd scripts/visualization
python create_presentation_charts.py
# Charts will appear in ../../charts/ folderIf you see Java version errors:
-
Install Java 17+:
- Windows: Download from Oracle
- Mac:
brew install openjdk@17 - Linux:
sudo apt install openjdk-17-jdk
-
Set JAVA_HOME:
# Windows set JAVA_HOME=C:\Program Files\Java\jdk-17 # Mac/Linux export JAVA_HOME=/usr/lib/jvm/java-17-openjdk
- Close other programs
- Start with smaller datasets (1M, 5M) first
- Make sure you have at least 8GB RAM for 50M row tests
Make sure you have the original custom_1988_2020.csv file and run the extraction script:
cd scripts/data_generation
python extract_real_world_datasets.pyEach benchmark runs these common data processing tasks:
- Loading - Reading a CSV file into memory
- Cleaning - Handling missing/null values
- Aggregating - Grouping data and calculating averages
- Sorting - Ordering data by values
- Filtering - Selecting rows that match conditions
- Correlations - Finding relationships between columns
These are the bread-and-butter operations you'll do with any real dataset!
- Polars is usually your best choice - It's fast, memory-efficient, and has a clean API
- Pandas is fine for small data - But switch to Polars when you hit performance issues
- Size matters - What works for 100K rows might be unusably slow for 10M rows
- Memory usage matters - Some libraries use 3x more RAM than others
- Real data tells the truth - These benchmarks use actual production data (113.6M rows from Japanese trade statistics 1988-2020), not synthetic data
- Test with your own data - While our results use real-world data, your specific use case may vary
- New to data processing? Start with the 1M row benchmark to see the basics
- Working with big data? Focus on the 50M row results
- Questions? Open an issue in this repository
Happy data processing! π
Remember: The best library is the one that solves your specific problem efficiently. But if you're unsure, Polars is a pretty safe bet these days!
All benchmarks in this project use real production data extracted from the custom_1988_2020.csv dataset:
- 113.6 million rows of actual Japanese trade statistics (1988-2020)
- 4.23 GB of real-world data with genuine patterns and distributions
- Subsets extracted: 1M, 5M, 10M, 50M, 100M rows for scalability testing
- Much more credible than synthetic benchmarks for research and production use cases