How to Access Columns by Name in Pandas (Python)

preview_player
Показать описание
↓ Code Available Below! ↓

This video shows how to access the columns of a pandas data frame using the name of the column. Although base python data structures like lists don't have index names, data frames have named columns that often give information about what is in the column, so it is usually more natural to select columns by name than a numeric index.

If you find this video useful, like, share and subscribe to support the channel!

Code used in this Python Code Clip:

import pandas as pd

# Access a column with direct indexing
mtcars["mpg"]

# Access a column with direct dot indexing

# Access multiple columns by name
mtcars[["mpg","cyl","hp"]]

# Access multiple columns by name with a subset of rows by row name

# Access multiple columns by name with a subset of rows by row index

* Note: YouTube does not allow greater than or less than symbols in the text description, so the code above will not be exactly the same as the code shown in the video! I will use Unicode large < and > symbols in place of the standard sized ones. .

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

ok then how can we filter this as to get values that's let's say have (in your dataframe) only 8 cylinders?

roneilboodie