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:

✅ Support My Channel Through Patreon:

✅ Become a Channel Member:

✅ One-Time Contribution Through PayPal:

✅ Cryptocurrency Donations:
Bitcoin Wallet – 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet – 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet – MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot

✅ Corey’s Public Amazon Wishlist

✅ Equipment I Use and Books I Recommend:

▶️ You Can Find Me On:
My Website –
My Second Channel –
Facebook –
Twitter –
Instagram –



Xem thêm bài viết khác:


  1. Sir,
    in this code

    import csv

    with open("new_data.csv", "w") as new_file:

    csv_writer = csv.writer(new_file, delimiter=".")

    csv_writer.writerow(["hi", "bye"])

    csv_writer.writerow(["yes", "no"])

    csv_writer.writerow(["good", "bad"])

    print("see the file")

    file new_data.csv




    the new line is coming after each writerow()
    why . . .. it should come like this



  2. So, a quick question..

    Why dont we use regex for reading whole doc here (by .*? Etc)
    if we can reach whole data in this way, why do we need csv methods?

  3. Hi all, At 15.16, Corey talks about creating a new dict only for first name and last name. I didn't quite get that, Can someone please elaborate. Thank you

  4. I have a CSV File with an extra column that has no Title. When I use the CSV.DictWrites, it throws me an error at fieldnames. How do i go about handling this.

  5. I have a question. What if I want to create a new csv file from blank with randomly generated users ? Is it doable through modifying the lines of code of this tutorial ?

  6. what can i do if the delimiter is in the string i want to save example:

    delimiter = ,

    and the email is = test,

    and I want to save it now = test,,name,alter

    then the test will be separated from test,

  7. When I write the code out you have at 15:42 I get a new csv file except, that there are new lines added in between every old line. So the amount of columns have doubled but every other one is empty.
    I'm using Pycharm – community edition btw.

  8. Hey Corey, How're you doing?

    I'm doing a csv generator for some performance tests. My code works fine for thousands of users, but when I try the same for millions of users execution becomes infinite.

    Can you help me please?

  9. Thank you so much!!
    Very great way of teaching, however while trying the same approach i observed that my "csv file" is not read completely (Out of 800 rows around 300 rows are missing). following is the code

    with open('BPU-A-073-00-upconversion.csv', 'r', newline='n') as input_data:

    csv_reader = csv.DictReader(input_data, delimiter = 't')

    for line in csv_reader:

    x_axis = line['Wavelength']

    y_axis = line['Intensity']


    Can anyone help me with this ? please!!

  10. 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 👍

  11. I need to write in the same file csv_reader but just needed to add new data on the last column with the same word each row. How?

  12. Thank you for this video, it was amazing.
    Can you please let me know how to write one element of row at one time in CSV file and not whole row at one go?


Please enter your comment!
Please enter your name here