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

preview_player
Показать описание
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.
Рекомендации по теме
Комментарии
Автор

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.

Mornepin
Автор

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 😄

jasinAmsterdam
Автор

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

TechMarketer
Автор

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

Bluwonder
Автор

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

WajidKhan-gnhj
Автор

I really appreciate this. Thank you so much!

bernardinojr.delacruz
Автор

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?

zzxp
Автор

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

connershafer
Автор

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

damegaye
Автор

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

CaseySmith-dv
Автор

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

takudzwaherbertmakopa
Автор

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

higiniofuentes
Автор

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

sameerpal
Автор

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

hazeleyes
Автор

How does the terminal printout work? around minute 7?

natedickinson
Автор

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

johnaweiss
Автор

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

christophercarr
Автор

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

karthikrajamony
Автор

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

CosD
Автор

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.

christopherjspiteri