Read CSV Files in Python with csv.DictReader - Iterate through Rows as Dicts with Columns as Keys

0:00 What are CSV files?
0:56 Tabular data saved from Excel spreadsheets to CSV files
1:35 CSV format is a plain-text format separated by comma delimiters
2:00 Rows and columns in CSV file formats
3:08 It is easy to write programs that can read CSV files
3:40 Import DictReader from csv in Python to read CSV rows into dictionaries
4:33 DictReader uses first row for keys of the dictionary returned for each row of values
5:23 Using the open function to establish a file handle to read a UTF-8 CSV file
5:57 For in loop over rows of a CSV file with a DictReader and print each row
8:35 Reading numerical data in a CSV file with DictReader and type casting
13:06 Find the average of a column in a CSV file in Python
14:45 Why write programs that process CSV files?
In this introductory tutorial you will learn about the CSV file format and how to write programs that make use of Python's built-in CSV library using the DictReader class. With these simple concepts, you will be able to write programs that process structured, tabular data that can be created or sourced from spreadsheet software or database software. Packages like Microsoft Excel and Google Sheets can save and produce CSV files from their Save As or Export File options. Popular database software can produce CSV files, too. When using a DictReader, all column values will be strings, and this video shows you how to intentionally convert column data to numerical data for further analysis. 3rd party libraries such as pandas will do these kinds of conversions automatically for you. Once you are comfortable with the idea of reading CSV files using this lower-level functionality, you are encouraged to make use of higher-level libraries such as pandas for day-to-day data processing and analysis.

Пікірлер: 36

  • @Mornepin
    @Mornepin3 жыл бұрын

    I was in a long trouble modifying a csv file, and I used the logic of your code to solve my issue ! THANK YOU. My god, hours of pain for that. What a relief.

  • @jasinAmsterdam1976
    @jasinAmsterdam19763 жыл бұрын

    Thank you so much. I just started my journey with python and just want to learn it for personal use. I really get what you are explaining here, and my brain is already drunk with the possibilities. I never knew that I could get excited about programming 😄

  • @TechMarketer
    @TechMarketer3 жыл бұрын

    Kirs, it's great tutorial - you show how things works and explain what is around. Thank you very much.

  • @Blu3wonder
    @Blu3wonder3 жыл бұрын

    Cheers for being so thorough! Hate not understanding WHY the code I'm typing works. Now Subscribed!

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

    Super demonstration.Thank you!

  • @WajidKhan-gn3hj
    @WajidKhan-gn3hj3 жыл бұрын

    Your explanation are very clear thanks for making them. It will help me alot.

  • @bernardinojr.delacruz5928
    @bernardinojr.delacruz59283 жыл бұрын

    I really appreciate this. Thank you so much!

  • @farhanahmad5934
    @farhanahmad59342 жыл бұрын

    Thanks, great video !

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

    Thank you for this very useful video!

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

    Exactly what I need !

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

    Great thank you!

  • @mikailstar4270
    @mikailstar42703 жыл бұрын

    Simple and useful

  • @zzxp1
    @zzxp13 жыл бұрын

    But how do you do that when you want to convert different types of data in each row. Lets say one column has a boolean, another an int, and another a string?

  • @connershafer6918
    @connershafer69183 жыл бұрын

    What if I needed to take a column of a csv file and count how many times a word occurs?

  • @xakeppro.548
    @xakeppro.5482 жыл бұрын

    Thanks man

  • @damegaye3051
    @damegaye30512 жыл бұрын

    Cool vidéo 😍 But how i do i want to print a single line by searching by the "precipitation" value for exemple ?

  • @CaseySmith-d5v
    @CaseySmith-d5v9 күн бұрын

    What if I want to keep the first column as a string and convert the following columns to floats?

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

    what if the dictionaries are not the same in terms of [str, float ] format and some are even [str, str] format????

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

    If the separator is not comma, something to be done to indicate that? Thank you!

  • @sameerpal2474
    @sameerpal24742 жыл бұрын

    Can we read columns of xml file which is inside csv file in python please reply

  • @christophercarr5865
    @christophercarr58653 жыл бұрын

    Check out the Rainbow CSV extension for VS Code. Makes csv files more human eyeball parseable.

  • @2hazeleyes
    @2hazeleyes Жыл бұрын

    Is the dictionary reader built in to the most recent version of python?

  • @johnaweiss
    @johnaweiss6 ай бұрын

    How can you look up key/value pairs without looping?

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

    How does the terminal printout work? around minute 7?

  • @Cos3D
    @Cos3D2 жыл бұрын

    how can we change a number in csv without it making the csv file unreadable ?

  • @christopherjspiteri
    @christopherjspiteri3 жыл бұрын

    How can we skip a header row in the csv file? i keep getting this: ValueError: could not convert string to float: 'Part' The word 'Part' is the first word in the csv file header.

  • @ajl240

    @ajl240

    3 жыл бұрын

    did you figure this out mate?

  • @brijeshsamal7035

    @brijeshsamal7035

    3 жыл бұрын

    the "next" function helps you with that.

  • @karthikrajamony6044
    @karthikrajamony60443 жыл бұрын

    Could you please share which theme and font you used in this video for VS Code

  • @KrisJordan

    @KrisJordan

    3 жыл бұрын

    Shades of Purple!

  • @karthikrajamony6044

    @karthikrajamony6044

    3 жыл бұрын

    @@KrisJordan thank you

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

    15:00 the day Apophis collided with earth

  • @tien9396
    @tien93962 жыл бұрын

    I give u 1 sub :)

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

    THERE IS NO NEED TO EXPLAIN A MILLION TIMES WHAT CSV´S ARE....

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

    Your video is not good for beginners