Pandas Read CSV by Column

preview_player
Показать описание
Learn how to read a CSV into Pandas by column. This allows you to read part of a CSV file instead of reading all the columns at once.

What is Pandas? A Python data analysis library

Even though the Jupyter notebook is wonderful. When you start to read in wide files, you start to notice some issues. when the file you are reading has a lot of column, things don't look that nice anymore. Now the exception are those of you who have really wide screens. But even so, if all you need to see is a few columns, then there is not point in reading in 1 columns.. right?

This video starts out by loading up into Pandas a tiny CSV file. If you have not seen my other video on reading a text file, go get it here:

Now I know that the file we placed in a dataframe has only three columns, but remember this is a tutorial and I want to make sure things are easily understood. The usecols parameter is introduced and this is the parameter that you will use to read in partially the CSV file. We read in the gender column alone. Only one column was read by simply passing in the name of the column.

We then read in the other columns once at a time, but uncovered an issue. Reading from a flat file might introduce spaces and other odd characters where you least expect them. Not a huge issue and we were able to overcome that data issue pretty easily.

Since the usecols parameter takes in a Python list, we could pass in multiple columns and you will get just those columns back. We also went over reading in files by position instead of by column name. This is wonderful as we don't always know the column names.

Рекомендации по теме
Комментарии
Автор

This is exactly what I needed. Btw the video is perfectly understandable at 2x speed 😁

infodat
Автор

Thank you for the video, help me so much.

juliomartinezsanchez
Автор

Congrats, this was really usefull to me

Joauluiz
Автор

if a column does not have any name then how can we get a column read

RizwanAli-xtmr
Автор

hello sir please help me out with a project which I have to submit ASAP. I can share you the screenshot of the project statement

mrigankopaul