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

Поделиться
HTML-код
  • Опубликовано: 6 июн 2024
  • 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.

Комментарии • 35

  • @Mornepin
    @Mornepin 3 года назад +10

    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.

  • @TechMarketer
    @TechMarketer 3 года назад +1

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

  • @jasinAmsterdam1976
    @jasinAmsterdam1976 3 года назад +4

    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 😄

  • @Blu3wonder
    @Blu3wonder 3 года назад

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

  • @WajidKhan-gn3hj
    @WajidKhan-gn3hj 3 года назад +2

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

  • @mehmedkukavica8076
    @mehmedkukavica8076 Год назад

    Super demonstration.Thank you!

  • @bernardinojr.delacruz5928
    @bernardinojr.delacruz5928 2 года назад

    I really appreciate this. Thank you so much!

  • @farhanahmad5934
    @farhanahmad5934 2 года назад +1

    Thanks, great video !

  • @higiniofuentes2551
    @higiniofuentes2551 11 месяцев назад

    Thank you for this very useful video!

  • @MayelPelle
    @MayelPelle Год назад

    Exactly what I need !

  • @mikailstar4270
    @mikailstar4270 3 года назад

    Simple and useful

  • @propilot7428
    @propilot7428 Год назад

    Great thank you!

  • @xakeppro.548
    @xakeppro.548 2 года назад

    Thanks man

  • @damegaye3051
    @damegaye3051 2 года назад +1

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

  • @zzxp1
    @zzxp1 3 года назад +1

    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
    @connershafer6918 3 года назад +3

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

  • @higiniofuentes2551
    @higiniofuentes2551 11 месяцев назад

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

  • @2hazeleyes
    @2hazeleyes Год назад

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

  • @natedickinson6489
    @natedickinson6489 Год назад

    How does the terminal printout work? around minute 7?

  • @takudzwaherbertmakopa4478
    @takudzwaherbertmakopa4478 Год назад +1

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

  • @johnaweiss
    @johnaweiss 5 месяцев назад

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

  • @sameerpal2474
    @sameerpal2474 2 года назад

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

  • @christophercarr5865
    @christophercarr5865 3 года назад +1

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

  • @Cos3D
    @Cos3D 2 года назад

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

  • @karthikrajamony6044
    @karthikrajamony6044 3 года назад

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

  • @christopherjspiteri
    @christopherjspiteri 3 года назад +2

    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.

  • @nadiarusiecki5785
    @nadiarusiecki5785 Год назад

    15:00 the day Apophis collided with earth

  • @tien9396
    @tien9396 2 года назад

    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