Python Tutorial: CSV Module - How to Read, Parse, and Write CSV Files

In this Python Programming Tutorial, we will be learning how to work with csv files using the csv module. We will learn how to read, parse, and write to csv files. CSV stands for "Comma-Separated Values". It is a common format for storing information. Knowing how to read, parse, and write this information to files will open the door to working with a lot of data throughout the world. Let's get started.
The code from this video can be found at:
github.com/CoreyMSchafer/code...
✅ Support My Channel Through Patreon:
/ coreyms
✅ Become a Channel Member:
/ @coreyms
✅ One-Time Contribution Through PayPal:
goo.gl/649HFY
✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
✅ Corey's Public Amazon Wishlist
a.co/inIyro1
✅ Equipment I Use and Books I Recommend:
www.amazon.com/shop/coreyschafer
▶️ You Can Find Me On:
My Website - coreyms.com/
My Second Channel - / coreymschafer
Facebook - / coreymschafer
Twitter - / coreymschafer
Instagram - / coreymschafer
#Python

Пікірлер: 744

  • @HellO-ly1bp
    @HellO-ly1bp7 жыл бұрын

    I've just interviewed for an amazing Python job, and if I get it I swear I will owe you so much. Everyone says this already but they're right, your videos are fantastic, thank you for all your time and effort!

  • @coreyms

    @coreyms

    7 жыл бұрын

    That's great, Nina! It makes my day to hear feedback like this. I wish you the best in getting the job. Good luck!

  • @HellO-ly1bp

    @HellO-ly1bp

    6 жыл бұрын

    So guess what... I got the job! Big big thanks again, it means so much to me to get a job like this. I'll be sure to keep on recommending your videos!

  • @syedabdulrahmans3357

    @syedabdulrahmans3357

    6 жыл бұрын

    Congrats Nina!

  • @HellO-ly1bp

    @HellO-ly1bp

    6 жыл бұрын

    I guess it's special to me because of the struggle it took to get here. My degree isn't in Computer Science, but I really wanted to get into programming and I thought it'd be too difficult to get my foot in the door. But the job I've just got is at a tier 1 investment bank as a Developer, so now I'll get to do something I enjoy for a job, get paid really well for it, and live/work in a beautiful part of London. Not a bad place to start!

  • @RockDavid

    @RockDavid

    5 жыл бұрын

    @@HellO-ly1bp Hey its been a year since you posted this. Im a CS well Computer ENgineer, and i learning this stuff for last 3 weeks goign for 3 months strait. I wanted to ask What did they ask about what you needed to know about Python and what are you constatnly doing at your job with Python? Like type of things your coding or editing? Thanks and its very late but grats on the job :)

  • @jedsonguedes
    @jedsonguedes4 жыл бұрын

    I gotta say: it's so rare to find someone with such a great ability for teaching. You should do another one for XML parsing.

  • @Xaminn
    @Xaminn4 жыл бұрын

    Every time I need help with a certain topic (and you've made a video on it), your video pretty much instantly solves my problem. I've spent an hour or so looking through forums and tutorials and this solved my issue in about 5 minutes. Thank you yet again for your expertise. 5/5

  • @jingyuchang1885
    @jingyuchang18856 жыл бұрын

    I just realized whenever I have a question about python, as long as I come to your channel, I can find the answer! Thanks very much!

  • @melissamejianisonger3860
    @melissamejianisonger38606 жыл бұрын

    I've spent a week trying to figure this out. I watched your video and it took me 10 minutes! THANK YOU. THANK YOU.

  • @tlrlutz
    @tlrlutz3 жыл бұрын

    Love the tutorials Corey they help so much in learning Python. Just thought I would update this video because the syntax is off around 8:00. The context manager "with open('new_names', 'w') as new_file:" will return a CSV file with a blank row in-between each row. The quick fix is to add "with open('new_names', 'w', newline='') as new_file:" and the issue goes away.

  • @francescob1904

    @francescob1904

    8 ай бұрын

    thanks you so much, I was wondering about what I did wrong...

  • @ugestacoolie5998

    @ugestacoolie5998

    6 ай бұрын

    @@francescob1904yeah me too and I was wondering why there was an extra line after each original line XD

  • @ourcore
    @ourcore2 жыл бұрын

    I hadn't touched Python in years and I've learnt so much from your videos about requests/requests-html, reading APIs, and CSV files. Thanks so much!

  • @Alex-ht1oq
    @Alex-ht1oq7 жыл бұрын

    You are so good at teaching man. I appreciate every video that you produce.

  • @ryaxn_a7495

    @ryaxn_a7495

    6 жыл бұрын

    nitty? oh, are you wondering why you have no friends? because when someone produces something absolutely amazing you don't notice it???

  • @shermanmerman4944

    @shermanmerman4944

    6 жыл бұрын

    it's a compliment. get over yourself.

  • @MyTube4Utoo

    @MyTube4Utoo

    6 жыл бұрын

    +JDI2002 Seriously, the guy pays Corey a much deserved compliment and you manage to find fault with it?

  • @CuriousAnonDev
    @CuriousAnonDev2 жыл бұрын

    Thank You sir, this lectures are still, in 2022, faaarrr more better than other so called tutorials It is difficult to believe someone gave such free high quality content years ago, you helped millions!!!! Thank You so so much

  • @vegito_blue6226
    @vegito_blue62265 жыл бұрын

    Hi Corey, thanks for this video. For my interview tomorrow this is what I was looking for.

  • @scochran3265
    @scochran32654 жыл бұрын

    What I love seeing in the below comments is people actually helping other people. There isn’t any bashing or calling each other names. Lovely.

  • @coreyms

    @coreyms

    4 жыл бұрын

    Yeah, when I first started making videos I was worried about the comments, but this community of people is fantastic. Super nice and helpful.

  • @superliang2887
    @superliang28875 жыл бұрын

    This video is the best, I watched many videos on KZread, only this one really help

  • @praveen0227
    @praveen02276 жыл бұрын

    I am a beginner in Python but whenever i watch your tutorials i feel its easy to write programs in python.The examples are very good. I wish if you can give some exercises based on the videos you show which will help beginners like me to write more programs.

  • @devslaven
    @devslaven5 жыл бұрын

    Any time I'm hunting for information on Python, my searches always lead to you and I'm never disappointed. Keep up the great work!

  • @user-zq4ix8ps6g
    @user-zq4ix8ps6g6 жыл бұрын

    best python tutorial I ever watched

  • @al-farabinagashbayev5403
    @al-farabinagashbayev54036 жыл бұрын

    if you have new csv file with blank lines this is for you # Python 2 with open('new_names.csv', 'wb') as outfile: writer = csv.writer(outfile) # Python 3 with open('new_names.csv', 'w', newline='') as outfile: writer = csv.writer(outfile)

  • @MilanRihaMilan

    @MilanRihaMilan

    6 жыл бұрын

    I had the same problem :P ...newline='' works just fine. Thank you. Great lectures, I really like the way you teach it. ;) not too fast, not too slow, good examples, easy to understand, really brilliant teaching skills ;)

  • @jamesgu9223

    @jamesgu9223

    5 жыл бұрын

    thank you, your way works fine.

  • @kitayuan9842

    @kitayuan9842

    5 жыл бұрын

    cheers brother

  • @sergiomedina5520

    @sergiomedina5520

    4 жыл бұрын

    I was spending 15 minutes to resolve it until you saved me with your comment. Thanks a lot!

  • @granberyacademia

    @granberyacademia

    4 жыл бұрын

    I wish I had read the comments... I couldn't understand why my code was f-ing me up

  • @valeriewang6244
    @valeriewang62446 жыл бұрын

    OMG Corey you are soooooo helpfullllllllllll. I love you!

  • @cringeyonmain
    @cringeyonmain4 ай бұрын

    Saved my life when doing my higher computing science coursework. Thanks so much!

  • @vergilfrans1447
    @vergilfrans14474 жыл бұрын

    Coding after long time...Feeling excited! Thank you for your tutorial. Easy to follow.

  • @soumyazyx
    @soumyazyx4 жыл бұрын

    Thank you Corey for your time and effort. Keep spreading the knowledge.

  • @ronitchawla4937
    @ronitchawla49374 жыл бұрын

    I am taking Harvard University's online CS50 course and I could understand JACK about CSV file till I saw this vid 😂 .... Thanks a lot man 👍

  • @mohammedadnan4976

    @mohammedadnan4976

    4 жыл бұрын

    SAME

  • @andrewpratt3861

    @andrewpratt3861

    3 жыл бұрын

    Me too!

  • @codingwithlucy

    @codingwithlucy

    3 жыл бұрын

    Me too :) just 5 months later

  • @jpdeveer

    @jpdeveer

    3 жыл бұрын

    I am taking the same course and have found the instruction to be quite lacking. I would be completely lost without Corey

  • @melancolique9835

    @melancolique9835

    3 жыл бұрын

    me toooo

  • @JV-jc7ci
    @JV-jc7ci Жыл бұрын

    You have a very, very simple teaching style that makes it easy for newbies to understand. You're a great teacher! Thank you for the awesome FREE tutorial! This was so much more useful than online courses I am paying for!

  • @auditocanarsie7355
    @auditocanarsie73552 жыл бұрын

    You are a natural professor. I appreciate the clarity & completeness. The text is easy to read on a desktop but was a little hard for me to read on a cell phone. If there was a way to zoom in on the text so it could be easier to read on a cell phone that is the only thing that could possible improve this video. Either that or I just need to visit my Optometrist and your videos are flawless.😀

  • @luminamoon504
    @luminamoon5042 жыл бұрын

    Total life saver, I needed this for a project due today, thank you so much!

  • @NazachatGames
    @NazachatGames3 жыл бұрын

    Corey, you make me have two interviews and real oportunities for a job, here in Argentina. Thanks you a lot. I'm now a member of your channel, hope u the best.

  • @elementalneil7967
    @elementalneil79672 жыл бұрын

    I was doing this Data Science course on Coursera, and the lesson on the csv module covered a load of content in a very short time. Of course, not understanding a thing, I had to revert back to KZread. This video clears it up really well. Thanks.

  • @TheFrazerboy
    @TheFrazerboy2 жыл бұрын

    excellent stuff definitly helping with my masters project

  • @aldrinmagnoa9874
    @aldrinmagnoa98743 жыл бұрын

    You make everything so simple to understand. thank you so much!

  • @MelanieCrypto
    @MelanieCrypto2 жыл бұрын

    refreshingly thorough and helpful ! thanks for posting this

  • @madyrebecca
    @madyrebecca6 жыл бұрын

    you're videos are magic !! i love watching them , thank you so much !!!!!!!

  • @MyTube4Utoo

    @MyTube4Utoo

    6 жыл бұрын

    +madyrebecca Corey's videos are 'magic.' I've started on Python books that just bored me. I've used Udemy, CodeCademy, other KZread videos, as well as countless other tutorials, but *nothing* has helped me nearly as much as Cory's tutorials. So yeah, "magic" applies here. I bet he's a warlock! lol

  • @QuarktaschemitSenf
    @QuarktaschemitSenf Жыл бұрын

    Thank you very much Corey. I switched job and now work with python. your videos helped a lot not to lose it in the beginning :-)

  • @hamidurrahman3183
    @hamidurrahman31836 жыл бұрын

    Brother Corey Schafer, your parents should be proud of you. You are a genius. Great at explaining. I have watched almost all videos of this python series. They are blessing to every python beginner. Thanks for all those videos.

  • @coreyms

    @coreyms

    6 жыл бұрын

    Thanks! I appreciate the kind words

  • @raybilton6995
    @raybilton69956 жыл бұрын

    Excellent series and I'm learning a lot from them. Your tutorials are my goto when I have a question. I really wish you had extended this video to include writing the two individual fields instead of just using delete. It would have helped with my needs more. I am working on a project with 20 fields in my input, but needing to write only 15 fields from the original file, and add two new fields to my 17 field output file.

  • @miquelr2353
    @miquelr23532 ай бұрын

    Thanks for being so clear. Learning by yourself can be like decyphering hierogrypics

  • @kirupv
    @kirupv5 жыл бұрын

    You covered very well through explaining simple way. Thank you very much

  • @letshev
    @letshev3 жыл бұрын

    Corey, you are the best. Thank you.

  • @connorpayne7324
    @connorpayne7324 Жыл бұрын

    very good, not only do you explain it very well, you explain each part of what you are doing and why. all in all a very good tutorial.

  • @timo_b3
    @timo_b32 жыл бұрын

    Awesome, thank you corey!

  • @shaunakalshi4547
    @shaunakalshi45474 жыл бұрын

    Thank you for the tutorial.Helped me a lot in my miniproject.

  • @danmuniz1354
    @danmuniz13545 жыл бұрын

    Thanks Corey. Very Helpful! Cheers!

  • @x0gucx
    @x0gucx9 ай бұрын

    Thank you SOOOO Much, even after 6 years this tutorial is so useful. my college professor just told use to do this with an article attachment and it's an intro class so I couldn't understand a single thing on there. THANK YOU FOR THE VIDEO TUTORIAL❣

  • @converti76
    @converti764 жыл бұрын

    Super useful! Thanks dude!

  • @MexicanPickleTamarindo
    @MexicanPickleTamarindo Жыл бұрын

    Better than my professor! Thank you.

  • @emilyncozzens8309
    @emilyncozzens8309 Жыл бұрын

    This is the best tutorial the I never found! Thanks so much!

  • @husseinabukar7081
    @husseinabukar70814 жыл бұрын

    Absolutely, fantastic video and simple to understand it. Many thanks for your time and efforts

  • @datag1199
    @datag1199 Жыл бұрын

    Great tutorial - thank you! Subscribed

  • @mahodaadikari4116
    @mahodaadikari4116 Жыл бұрын

    Thanks for the wonderful explanation ❤💫💪🏼

  • @AK-kj8cc
    @AK-kj8cc6 жыл бұрын

    You are very thorough in your explanations. I've subbed and I hope you keep this up!

  • @kimberlybacchia1413
    @kimberlybacchia14135 жыл бұрын

    SO helpful, thank you!!

  • @shivrankrishen
    @shivrankrishen3 жыл бұрын

    Short and down to the point.You Sir you're a God Sent.

  • @praveenmishra5822
    @praveenmishra58222 жыл бұрын

    Nice explanation, Thanks!

  • @michaelpadovani9566
    @michaelpadovani95667 жыл бұрын

    Hey thanks for posting this, I'm very new to Python (and watched a lot of your other tutorials). I'm a meteorologist that works with instrumentation datasets so i live and breathe HUGE csv files lol Hoping to use this method tutoring a local HS student for his project. Thx again and cheers from Maryland!

  • @tobbysorama
    @tobbysorama6 жыл бұрын

    You are an awesome tutor!

  • @ozodbekulashov2325
    @ozodbekulashov23254 жыл бұрын

    Hello Mr Corey ! Thanks for this incredible content!

  • @sameerk12982
    @sameerk129826 жыл бұрын

    Thank you very much Sir for creating such an easy to understand tutorial about reading writing csv file.

  • @egonz7194
    @egonz71943 жыл бұрын

    just what i needed for my problom set thanks bro .

  • @impact_k
    @impact_k11 ай бұрын

    This is fantastic, no lies. Thank you very much

  • @karmendurbin
    @karmendurbin2 жыл бұрын

    Amazing explanation.

  • @drewconroy5938
    @drewconroy59387 жыл бұрын

    Great stuff as always - Thank you:)

  • @navidpanchi
    @navidpanchi6 жыл бұрын

    Thank you so much for such a wonder full series!

  • @prateekmohanty8315
    @prateekmohanty83152 жыл бұрын

    Amazing video man , thank you so much

  • @crystalramirez2550
    @crystalramirez2550 Жыл бұрын

    Thank you so much for these amazing videos.

  • @mediumshrimp9696
    @mediumshrimp96963 жыл бұрын

    I have never seen a negative comment on your videos. You are helping me get through this coding boot camp like you'll never believe. Thanks, Mr. Corey.

  • @okayest_pianist

    @okayest_pianist

    3 ай бұрын

    how'd the bootcamp go bruh

  • @mediumshrimp9696

    @mediumshrimp9696

    3 ай бұрын

    @okayest_pianist For me it was worth it. My class size was 17 or 19 and only two didn't get jobs right before/after graduation. Several of my classmates are going to college either while online/in person to get degrees. It is hard, our starting class size was 28. In my opinion, it's the way to go.

  • @okayest_pianist

    @okayest_pianist

    3 ай бұрын

    @@mediumshrimp9696 love to hear it brother. glhf

  • @atienograce2520

    @atienograce2520

    3 ай бұрын

    I’ll be joining a data analytics bootcamp this September and this comment gave me hope.Yes,it won’t be all rosy but it will be worth it!Thank you!

  • @simonnguyen692
    @simonnguyen692 Жыл бұрын

    sick tutorial man thank you

  • @FisVii77
    @FisVii776 жыл бұрын

    man you are a very good python presenter, keep up the great work and vids.

  • @GiovanniGirelli1104
    @GiovanniGirelli11044 жыл бұрын

    Hello Corey, I just discovered your channel today and it is awesome. Funny that you cover all the topics I am interested in (Python, SQL, Pandas, MatPlotlib etc). For people like me who never even came close to going to college/university this is awesome. One topic I would really like to see would be a tutorial on (if at all possible) automating the process of extracting tabular data from PDF's using Python and convert them into useful Excel files (something I need to do on a daily basis at work). Awesome channel, keep it up!

  • @yingbowang3068
    @yingbowang30683 жыл бұрын

    exactly what i want,Thanks !!

  • @andres-beltre
    @andres-beltre5 жыл бұрын

    Thank you so much for the sucint tutorial. This precisely what I needed!

  • @amanuelsiyum4537
    @amanuelsiyum45375 жыл бұрын

    Very helpful videos, keep up the good work!!!!!

  • @chescodrc
    @chescodrc3 жыл бұрын

    Thank you so much for this video!

  • @diggable
    @diggable6 жыл бұрын

    awesome, my first CSV read\write tutorial! thank you sir! -------------------------

  • @daisycarranza4034
    @daisycarranza4034 Жыл бұрын

    Thank you so much I needed this

  • @goldenogregames
    @goldenogregames3 жыл бұрын

    For anyone getting spaces between lines using writerow method ( using python 3 ), you need to add newline=' ' inside open like this, open('file.csv', 'w',newline=' ') as ... : (the second with open iteration)

  • @abbasali9730

    @abbasali9730

    3 жыл бұрын

    thanks man

  • @jakubb2066

    @jakubb2066

    11 ай бұрын

    thx

  • @ruizhenmai1194
    @ruizhenmai11946 жыл бұрын

    concise and clear! thx so much

  • @jykw1717
    @jykw17177 жыл бұрын

    YOU ARE GOD OF PYTHON

  • @ricardolazaro1766
    @ricardolazaro17664 жыл бұрын

    Awesome video, I very easy to understand! Thank you for the awesome video!

  • @takibahmed8859
    @takibahmed88592 жыл бұрын

    Thank you for this lecture

  • @cyperdevelopment
    @cyperdevelopment5 жыл бұрын

    Your introduction voice is amazing!

  • @organizedchaos4559
    @organizedchaos45593 жыл бұрын

    Great video, very informative and helpful. You make it really easy to follow and understand

  • @hadishaaben3665
    @hadishaaben36654 жыл бұрын

    You are Awesome i used thes codes as a mad man .. I loved it

  • @omkarkhare4542
    @omkarkhare45426 жыл бұрын

    Very well explained

  • @muhammadnaveedkhan6739
    @muhammadnaveedkhan67392 жыл бұрын

    Excellent work Sir, Your teaching style is awesome.

  • @YourSvetlana
    @YourSvetlana11 ай бұрын

    Thank you for the video 😊

  • @PrashantKumar-ks2rd
    @PrashantKumar-ks2rd5 жыл бұрын

    really helpful video thank you!!

  • @fubli4real
    @fubli4real3 жыл бұрын

    Nice vid, helped a lot!

  • @claylanzino9749
    @claylanzino97493 жыл бұрын

    Very interesting. Thanks 👍 for sharing.

  • @muralidhar40
    @muralidhar40 Жыл бұрын

    I can not quite put the finger around it, but your teaching is magical!

  • @sahilahuja6574
    @sahilahuja65744 жыл бұрын

    Great video, good job!!

  • @Imran20091990
    @Imran200919902 жыл бұрын

    Before watching Corey video.. i always hit like..

  • @prmoreiit
    @prmoreiit6 жыл бұрын

    Highly engaging..Kudos!!

  • @peterfconley
    @peterfconley Жыл бұрын

    Thank you so much.

  • @asifahussain899
    @asifahussain899 Жыл бұрын

    U are great Corey Sir ... waiting for Ur 1 million subscribers ❤️

  • @sphiwemodise5713
    @sphiwemodise57134 жыл бұрын

    Thank you. This is helpful

  • @mjprescotti
    @mjprescotti3 жыл бұрын

    This video was worth the viewing I wish I had found this days ago:)

  • @johnpitic1124
    @johnpitic11245 жыл бұрын

    Thank you man i will pass my gcse

  • @cristianomendoncagueivara5702
    @cristianomendoncagueivara57023 жыл бұрын

    Thanks for this video!!!!

  • @mirulj7072
    @mirulj70722 жыл бұрын

    I really like this video thank you so much

  • @GabrielSilva-mv4fm
    @GabrielSilva-mv4fm2 жыл бұрын

    Great video, thx!

  • @zorojuro5106
    @zorojuro51064 жыл бұрын

    thanks brother

  • @zrwashehzadi8890
    @zrwashehzadi88903 жыл бұрын

    Thank you so much man..