Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Master Data Science with Python

Lesson 20 of 60 · python

Writing Data: Exporting DataFrames

Duration: 15 minutes

Exporting DataFrames

After processing, you often need to save results.

To CSV

df.to_csv('output/cleaned.csv', index=False)

To Excel

df.to_excel('output/report.xlsx', sheet_name='Summary', index=False)

To JSON

df.to_json('output/data.json', orient='records', lines=True)

To SQL (using SQLAlchemy)

from sqlalchemy import create_engine
engine = create_engine('sqlite:///mydb.sqlite')
# Write DataFrame to a table called "sales"
df.to_sql('sales', con=engine, if_exists='replace', index=False)

Compression

df.to_csv('output/compressed.csv.gz', compression='gzip')

Info

When sharing data, consider to_parquet for columnar storage and faster I/O.

df.to_parquet('output/data.parquet')
```</Alert>
Previous: Reading Data: CSV, Excel, JSON, and MoreNext: Selecting & Filtering Data in Pandas