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 by omitting a component of the slice specifier.
To start demonstrating slicing, we will use the following Series:
We can select consecutive...