CSV Files with Python — Reading and Writing

preview_player
Показать описание
Learn to read and write CSV files with Python by using the built-in csv module. We'll also learn about CSV named columns by using csv.DictReader and csv.DictWriter.

CSV files are comma-separated files. That means that by using commas, we split the file into columns. We can use Python to read CSV files by going through the file line by line, and then splitting each line into its columns by using the comma as a delimiter.

Alternatively we can use the csv module in Python to read CSV files more easily.

Using the csv module has a few advantages, such as simplifying your code, making it more efficient, and also dealing with pesky edge cases like when you have commas in the data you want to write to the CSV.

-- Links mentioned in the video --

✅ Blog post on slicing

✅ The csv module documentation

✅ Support us and learn by taking our Complete Python Course

✅ Subscribe to our channel for more content. We release new videos weekly!

Hope you've learned how to read and write CSV files with Python in this video.

Thank you for watching!
Рекомендации по теме
Комментарии
Автор

hey Jose!
I am completing your course on Udemy. I am 13 years old and I am enjoying it...

thunderwolf
Автор

Jose, your Complete Python Course on Udemy is awesome man; It;s engaging and well explained. Thanks!

danieltamayo
Автор

For newbies like me, according to Stackoverflow, if you get an extra line (Windows specific issue):

either: with open('file.csv', 'w', newline='') as f: # Note the newline = ' ' (added a space for readability)
or: writer = csv.writer(f, lineterminator='\n')


PS: @Teclado. Really liking and learning a lot from your Udemy course.

seamusmcmillen
Автор

Enjoy the video guys! Bit of a different format this time. I wanted to be more practical to show you a simple yet powerful built-in module that solves a problem many of have on the daily!


Are there any built-in modules you find interesting that are less known? Let me know, and we can make a video about them.

tecladocode
Автор

Hi, just wanted to say thanks for reviving the channel again! You CS4Everyone playlist has helped my siblings with school a lot! Hope to see more from you in the future, just started getting into Python myself as its sort of becoming the industry standard and this is pretty interesting!

AryanshMalviya
Автор

hey Jose!
What is the output parameter that you are passing to the function write_to_file

niranjanraje
Автор

Hi Jose!
i am going through your course for complete Python on Udemy, i am not able to post a question in Udemy as i got the course from my company.
i have a doubt in Milestone project 2 storing books in json files, the code runs fine for fist time but when we re-run the code again the books.json files becomes empty.
Please look into that.

yeswanthyenamula
Автор

i don't know why my code runs and shows nothing

ShriVrindavaneswari
Автор

Hello!
if I open file for writing with ' with open('file.csv', 'w') as f " I get in file.csv

kanatatygayev
Автор

"output" has never been defined. "matrix" was never referenced. Did you get im from memory from previous runs?

sinkingboat
Автор

Hi, Don't you have to close the files in the code?

kentClimber
Автор

Hi Jose! I am getting an error while saving data into CSV format
In your course content 50. i am getting an error while executing app.py the code is "f.write("{}, {}, {}\n".format(movie.name, movie.genre, str(movie.watched)))"
Please resolve

PankajKumar-vgpk