Locked lesson.
About this lesson
We discuss how to select individual and multiple columns within a data frame.
Exercise files
Download this lesson’s related exercise files.
Selecting Columns and Multiple Columns.docx57.4 KB Selecting Columns and Multiple Columns - Solution.docx
55.4 KB
Quick reference
Selecting Columns and Multiple Columns
Selecting data from a column or specific columns is easy!
When to use
Use this whenever you need to select a column of data, or multiple columns.
Instructions
Given a dataframe named my_df with columns:
my_cols = ["Mon", "Tues", "Wed"]
To grab a specific column, such as 'Tues':
my_df["Tues"]
To Grab more than one column, pass a list of lists:
my_df[["Mon", "Wed"]]
Hints & tips
- Grab One Column: my_df["Tues"]
- Grab More Than One Column: my_df[["Mon", "Wed"]]
Lesson notes are only available for subscribers.