Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Writing CSVs With Python's "csv" Module

Give Feedback

In this lesson, you’ll learn how to write data to CSV files using the two csv writer methods csv.writer and csv.DictWriter. The lesson also covers how to quote specific fields using constants such as csv.QUOTE_MINIMAL, csv.QUOTE_NONNUMERICand, csv.QUOTE_NONE.

Robert on July 1, 2019


What is the IDE or editor that you are using?


Joe Tatusko RP Team on July 5, 2019

Hi Robert! I’m using Atom and platformio-ide-terminal for the integrated terminal at the bottom in these videos.

Robert on July 9, 2019

Thank you, I’ll check those out

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')

hayatmor on March 15, 2020

In python3 in order to work without double space you shall add:

with open('employee_file.csv', mode='w', newline='') as employee_file:

Source: Stackoverflow

sweir12525 on Sept. 24, 2020

Hi, I got a reply to a prior question regarding why I am getting a syntax error when I put in pip install pandas. The RP Team member, Bartosz, answered telling me what a csv file was and that any text editor can open them. Problem is that I know exactly what a CSV file is, I am using PYcharm and Thorny and on both applications, when I enter the script in this lesson, I get a syntax error. I have installed Anaconda and when I put in the entire script I get attribution error. When I debug, it says I should try calling something other than pandas. So, please explain to me what I am doing wrong since all I am doing is following the lesson plan.

Ricky White RP Team on Sept. 25, 2020

Hi @sweir12525. It might be useful in this case if you copy the bottom part of the Traceback error. Just above where it says Syntax error, it’ll show you which line of code is causing the problem. It would be helpful if we could see that so we can help you further.

Become a Member to join the conversation.