O'Reilly logo

Learning pandas by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Slicing a Series

In Chapter 3, NumPy for pandas, we covered techniques for NumPy array slicing. pandas Series objects also support slicing and override the slicing operators to perform their magic on Series data. Just like NumPy arrays, you can pass a slice object to the [] operator of the Series to get the specified values. Slices also work with the .loc[], .iloc[], and .ix properties and accessors.

To demonstrate slicing, we will use the following Series:

In [83]:
   # a Series to use for slicing
   # using index labels not starting at 0 to demonstrate
   # position based slicing
   s = pd.Series(np.arange(100, 110), index=np.arange(10, 20))
   s

Out[83]:
   10    100
   11    101
   12    102
   13    103
   14    104
   15    105
   16    106
   17    107
   18    108
   19    109
   dtype: int64

The ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required