← Courses

Pandas, Hands-On Data with Python

Data Science

Core pandas · Lesson 4 of 10

Indexing, selecting and assigning

Getting the data you want

Once you have a DataFrame, you need to pull out the parts you care about.

  • Select one column with square brackets: df["score"]
  • Select rows by position with iloc
  • Select rows by label or by a condition with loc
Python

That last line is the most useful pattern in all of pandas: filtering rows by a condition.

Exercise

Exercise — check your understanding

From the students DataFrame in the starter, select only the rows where city is "Lagos" and store them in lagos.

You’re reading for free. Sign in to keep your progress and earn a certificate when you finish.Sign in to keep my progress →