Export Data to Parquet & Feather
Export Results to Parquet and Feather — Data Analysis with Python.
Focus: export results to parquet and feather
You’ve just spent hours cleaning, transforming, and reshaping your dataset, and now you need to save the results. The temptation is to write everything to a CSV and move on. But CSV files crush data types, bloat file size, and take forever to load. If you’ve ever opened a 2 GB CSV and watched your laptop beg for mercy, this lesson is for you. Today, you’ll learn how to export results to Parquet and Feather — two modern columnar formats that are faster, smaller, and more type-preserving than CSV, so you can share and reuse your analysis without the pain.
The Problem This Lesson Solves
In real data analysis, the pain is real: CSV is the default export format, and it’s terrible for anything beyond trivial datasets. Parquet and Feather solve this by storing data in a binary, columnar format that preserves dtypes, compresses well, and loads at lightning speed. For example, a 500 MB CSV might compress to 80 MB in Parquet, and reading a Parquet file can be 5–10x faster than reading the equivalent CSV. This lesson shows you exactly how to export results to Parquet and Feather, so you can stop wrestling with CSVs and start working smarter.
Core Concept / Mental Model
Think of CSV as a plain-text inventory list: human-readable, but slow to process and easy to misread (e.g., a date string that gets interpreted as text). Parquet and Feather are like a zip file with a built-in index — they store data in a binary columnar format, which means computations can skip columns you don’t need and load only the rows that matter.
- Parquet is a compressed, columnar storage format widely used in big data (Spark, Hadoop, cloud data lakes). It supports complex nested data and is optimized for storage efficiency.
- Feather is an IPC (InterProcess Communication) format, designed for speed — it writes and reads data nearly as fast as the filesystem will allow, making it ideal for quick transfer between Python and R or for caching intermediate results.
The key insight: format choice matters more than you think. Exporting results to Parquet or Feather isn’t just about saving a file — it’s about preserving your data’s integrity and making future analysis faster.
How It Works Step by Step
Here’s the logical sequence to export a pandas DataFrame to Parquet or Feather:
- Import pandas and ensure you have the right engine — pandas uses
pyarroworfastparquetas backends for Parquet, andpyarrowfor Feather. - Call the right methods — for Parquet:
df.to_parquet('file.parquet'); for Feather:df.to_feather('file.feather'). - Check dependencies — if you haven’t installed
pyarrow, runpip install pyarrowto use both formats. - Verify the output — reload with
pd.read_parquet()orpd.read_feather()to ensure data integrity. - Consider file size and speed — you can tweak compression (e.g.,
snappyfor Parquet) to balance size vs. write time.
Visual analogy: Saving to CSV is like writing a novel by hand — slow and error-prone; saving to Parquet is like sending a PDF — fast, compact, and ready to read.
Hands-On Walkthrough
Let’s export results to Parquet and Feather with real code. First, make sure you have the required libraries:
pip install pandas pyarrow
Now, create a sample DataFrame and export it to both formats:
import pandas as pd
import numpy as np
# Create a sample DataFrame with mixed dtypes
np.random.seed(42)
df = pd.DataFrame({
'id': range(1000),
'category': np.random.choice(['A', 'B', 'C'], size=1000),
'value': np.random.randn(1000),
'timestamp': pd.date_range('2024-01-01', periods=1000, freq='h')
})
# Export to Parquet
df.to_parquet('results.parquet', index=False)
print('Parquet file saved.')
# Export to Feather
df.to_feather('results.feather')
print('Feather file saved.')
Now, read them back and verify they’re identical to the original:
# Read back the files
parquet_df = pd.read_parquet('results.parquet')
feather_df = pd.read_feather('results.feather')
# Check equality
print(parquet_df.equals(df)) # True
print(feather_df.equals(df)) # True
# Check dtypes are preserved
print(df.dtypes)
print(parquet_df.dtypes)
Expected output (simplified):
True
True
id int64
category object
timestamp datetime64[ns]
...
You can also specify compression for Parquet to reduce file size further:
# Use gzip compression for smaller files (but slower)
df.to_parquet('results_compressed.parquet', compression='gzip')
Pro tip: Always set
index=Falsewhen exporting to Parquet if you don’t need the index — it keeps the format clean and avoids surprises when reading back.
Compare Options / When to Choose What
Not every format fits every job. Here’s a practical comparison:
| Format | Best for | File size | Read/write speed | Dtype preservation | Ecosystem support |
|---|---|---|---|---|---|
| CSV | Human-readable, spreadsheets | Large | Slow | Poor (strings, dates) | Universal |
| Parquet | Big data, cloud storage, long-term archives | Small (compressed) | Fast (columnar) | Excellent | Spark, Hive, AWS, GCP |
| Feather | Quick data exchange between Python/R, caching | Medium | Very fast | Excellent | Python, R, Julia |
When to choose what: Use Parquet when you’re storing data for later analysis in a distributed system or cloud. Use Feather when you need to move data between processes or notebooks quickly and want maximum speed. CSV is still fine for sharing with non-technical users, but for everything else, prefer binary formats.
Troubleshooting & Edge Cases
ImportError: missing pyarrow— Install it:pip install pyarrow. If you’re usingfastparquet, install that instead.TypeError: object of type ... is not supported— Some pandas dtypes (likecategorywith unknown categories) may not round-trip. Convert to string or numeric before export if you encounter this.- Feather doesn’t support nested data — Parquet handles nested columns; Feather is for flat data. If you have dicts in columns, stick to Parquet.
- **
to_parquetwithindex=False— If you forget to set it, the index becomes a column on read-back, which can cause schema mismatches. Always be explicit. - Large files and memory — Loading a huge Parquet file may still be heavy. Use
columnsparameter to load only certain columns:
# Read only a few columns
subset = pd.read_parquet('results.parquet', columns=['id', 'value'])
What You Learned & What’s Next
You now know how to export results to Parquet and Feather using pandas, preserving data types and making your workflows faster. You’ve mastered the core concepts, step-by-step coding, and troubleshooting. These binary formats are essential for any serious data analysis, especially when dealing with large datasets.
Next, you’ll learn how to import data from API responses — turning JSON into tidy DataFrames, so you can pull live data into your analysis pipelines. With your new export skills, you’ll be ready to build efficient, reproducible workflows from data collection to final output.
Practice recap
Try exporting a large dataset (e.g., >100 MB) to CSV, Parquet, and Feather. Compare file sizes and timings on load. Then, create a small DataFrame with columns of different dtypes and round-trip it through each format, checking that dtypes stay the same. This hands-on exercise will cement the concepts.
Common mistakes
- Forgetting to install
pyarroworfastparquetand gettingModuleNotFoundError— always check your environment. - Not setting
index=Falsewhen exporting, which adds an unnamed index column that can break downstream schemas. - Using Feather for nested or dictionary-like data when Parquet is required — Feather is for flat data only.
- Assuming CSV is good enough for large datasets, then hitting slow load times and dtype issues later.
Variations
- Use
fastparquetinstead ofpyarrowas the Parquet engine — lighter weight for some setups, but with fewer features. - Export to Parquet via
df.to_parquetwithcompression='gzip'vs. defaultsnappy— trade-off between size and speed. - Use
pyarrow.parquet.write_tabledirectly for more control over chunking and schema when working with huge data.
Real-world use cases
- Saving a cleaned dataset to Parquet for reuse in a Spark analytics pipeline, reducing load time from minutes to seconds.
- Caching intermediate analysis results as Feather in a Jupyter notebook to avoid recomputing expensive transformations.
- Storing daily log aggregations in Parquet on AWS S3, integrating with Athena for SQL queries.
Key takeaways
- Parquet and Feather preserve dtypes, compress well, and load faster than CSV.
- Use
df.to_parquet()anddf.to_feather()to export results; installpyarrowfor both. - Feather is fastest for IPC and flat data; Parquet is better for complex data and big data ecosystems.
- Always verify your export by reading it back and checking equality with the original DataFrame.
- Compression options like
gzipreduce file size at the cost of speed; choose wisely. - Understanding these formats is key for building scalable data pipelines.