Accessing elements from series with position in pandas



Accessing elements from series with position is called as slicing.First we want to create a list.Next we want to convert the list into array by using np.array in the numpy concepts for that we want to import the numpy.Next we want to convert the array into pandas series by using pd.series in the pandas concepts for that we want to import the pandas.Then we can slicing the pandas series.








Example-1
import pandas as pd
import numpy as np

a = np.array([ "m", "y", "c", "r", "a", "z", "y"])

n = pd.Series(a)

print(n[2:])



Output



2    c
3    r
4    a
5    z
6    y
dtype: object







Example-2
import pandas as pd
import numpy as np

a = np.array([ "m", "y", "c", "r", "a", "z", "y"])

n = pd.Series(a)

print(n[:2])



Output



0    m
1    y
dtype: object