Selecting rows
When we are taking the measure of our data and otherwise answering the question, “How does it look?”, we constantly zoom in and out and look at aggregated numbers and particular rows. But there are also important data issues that are only obvious at an intermediate-zoom level, issues that we only notice when looking at some subset of rows. This recipe demonstrates how to use pandas tools to detect data issues in subsets of our data.
Getting ready...
We will continue working with the NLS data in this recipe.
How to do it...
We will go over several techniques for selecting rows in a pandas
DataFrame:
- Import
pandas
andnumpy
, and load thenls97
data:import pandas as pd import numpy as np nls97 = pd.read_csv("data/nls97.csv") nls97.set_index("personid", inplace=True)
- Use slicing to start at the 1001st row and go to the 1004th row.
nls97[1000:1004]
selects every row starting from...