Slicing is an accessing technique or method in which we can access a particular part of series. If we consider whole series as a set, then using slicing we can access subset of that particular series using the start and the end index. Basically, it is useful in extrating a particular part of series.
SYNTAX: print(ser_name[start_index:end_index])When slicing is done using positional indices that is default indices, the end index(extreme) is excluded in selection and when slicing is done using user-defined indices, the end index(extreme) is included in selection.
#importing required libraries
import pandas as pd
#creating a list of names
list1 = ['Aman', 'Raghav', 'Shubham', 'Rohit', 'Yash']
ser = pd.Series(list1)
#accessing element of the series through slicing
print(ser[2:4])
2 | Shubham |
3 | Rohit |
dtype: | object |