Skip to main content
Albero Academy

Reading & Writing Formats

Beyond CSV — Parquet, SQL databases and efficient storage.

Applied Pandas8 min

CSV is universal but slow and lossy (everything is text). For real pipelines, pandas reads and writes efficient binary formats and talks to databases directly.

Parquet over CSV

fast, typed, compressed
df.to_parquet("data.parquet") # columnar, compressed, keeps dtypes
df = pd.read_parquet("data.parquet") # much faster than CSV to reload

Databases

read_sql / to_sql
df = pd.read_sql("SELECT * FROM students WHERE package > 7", conn)
df.to_sql("results", conn, if_exists="replace", index=False)

Key takeaways

  1. 01Parquet is columnar, compressed, typed and much faster than CSV to reload.
  2. 02read_sql / to_sql move data between pandas and databases.
  3. 03CSV is universal but slow and loses dtypes; prefer Parquet for your own pipelines.
  4. 04Choose the format by audience: Parquet for pipelines, CSV for interchange.

Finished this chapter?

Mark it complete to track your progress through Pandas.