Manipulating Series Objects

Let’s see how we can use slicing and vectorization operations to manipulate the Series objects.

Basic slicing and indexing

A series supports the basic slicing and indexing operations just like the Numpy ndarray and the native Python list types.

Integer Index

With the [] operation, you can access the specified value by its location, which is an integer index. Just like accessing an element in a native Python list.

Slice object

start:stop:step is an object that contains a portion of a sequence.

  • If only stop is provided, it generates a portion of a sequence from index 0 to stop, where stop is excluded.
  • If only start is provided, it generates a portion of the sequence after the index start until the last element.
  • If both start and stop are provided, it generates a portion of the sequence after the index start until the stop where the stop is excluded.
  • If start, stop, and step are provided, it generates a portion of the sequence after the index start until stop with an increment of index step.

List of indexes

Sometimes, we want to get multiple elements from a Series with multiple indexes; however, there is no pattern between them. You can pass a list of indexes to a Series object with the [] operation to get those elements.

Get hands-on with 1400+ tech skills courses.