Lesson 1 ❮ Lesson List ❮ Top Page
❯ 1.3 Rows Selection
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
EXPECTED COMPLETION TIME
❲▹❳ Video 6m 27s
☷ Interactive readings 5m
Let's read in the college dataset with the institution name as the index, and select a single column as a Series with the indexing operator.
The .iloc indexer makes selections only by integer location. Passing an integer to it returns a scalar value.
To select several different integer locations, pass a list to .iloc. This returns a Series.
To select an equally spaced partition of data, use slice notation.
Unlike .iloc, the method .loc selects only with index's name or labels.
Passing a single string returns a scalar value.
To select several disjoint labels, use a list.
To select an equally spaced partition, use slice notation. Make sure that the start and stop values are strings. You can use an integer to specify the step size of the slice.
Here, we will see how to do the same thing with the two indexers, .iloc and .loc. Notice the difference.
To select a disjointed set of rows as a DataFrame, pass a list of integers to the .iloc indexer.
The same DataFrame may be reproduced using .iloc by passing it a list of the exact institution names.
The slice notation can be used with .iloc to select an entire segment of the data.
Slice notation also works with the .loc indexer and is inclusive of the last label.