Slicing a Series into subsets

pandas Series support a feature called slicing. Slicing is a powerful way to retrieve subsets of data from a pandas object. Through slicing, we can select data based upon position or index labels and have greater control over the sequencing of the items that result (forwards or reverse) and the interval (every item, every other).

Slicing overloads the normal array [] operator (and also .loc[], .iloc[], and .ix[]) to accept a slice object. A slice object is created using a syntax of start:end:step, the components representing the first item, last item, and the increment between each item that you would like as the step.

Each component of the slice is optional and provides a convenient means to select entire rows ...

Get Learning pandas - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.