Locked lesson.
About this lesson
In this video, we'll discuss two different ways to select a row within a data frame, including the loc function.
Exercise files
Download this lesson’s related exercise files.
Selecting Rows.docx57 KB Selecting Rows - Solution.docx
55.4 KB
Quick reference
Selecting Rows
There are two main ways to grab Rows in a DataFrame: loc() and iloc().
When to use
Use either of these methods to grab the data from a row in a DataFrame.
Instructions
To grab a row named "Bob" in a DataFrame named my_df:
my_df.loc["Bob"]
To grab a row by its index, assuming Bob is the first row in the DataFrame:
my_df.iloc[0]
Hints & tips
- my_df.loc["Bob"]
- my_df.iloc[0]
Lesson notes are only available for subscribers.