Manipulating Series Objects
Let’s see how we can use slicing and vectorization operations to manipulate the Series objects.
We'll cover the following
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 indexstart
until the last element. - If both start and stop are provided, it generates a portion of the sequence after the index
start
until thestop
where the stop is excluded. - If
start
,stop
, andstep
are provided, it generates a portion of the sequence after the indexstart
untilstop
with an increment of indexstep
.
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.