Reading and Writing CSV Files

This short course teaches how to read and write data to CSV files using Python’s built in csv module and the pandas library. You’ll learn how to handle standard and non-standard data such as CSV files without headers, or files containing delimiters in the data.

At the end of the course there will be an optional quiz to check your learning progress.

What’s Included:

Downloadable Resources:

Related Learning Paths:

About Joe Tatusko

Joe Tatusko Joe Tatusko

Joe is a manufacturing engineer turned Pythonista with interests in data wrangling and visualization.

» More about Joe

Each tutorial at Real Python is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

Participant Comments

Dave Wilson on Feb. 23, 2020

Such a great tutorial, Joe - as always!

I’m not sure why, but my csv’s printed rows on every other line. I was able to fix it by adding a lineterminator to the employee_writer definition: employee_writer = csv.DictWriter(employee_file, fieldnames=fieldnames, lineterminator = '\n')

The Cool Ghoul on Sept. 17, 2019

I really like the tip about using the DictReader . Never knew that existed. I routinely read large CSV datasets. So this will be a big time saver and improve readability of my code.

SamR on June 17, 2019

Very helpful information. Thank you!

« Browse All Courses