Accessing Element Using Label index in pandas
Accessing element using label is called as index. First we want to create a list. Next we want to convert the array into pandas series by using pd.series in that we want to pre definedly assign the index value based on any values to the index in the pandas concepts for that we want to import the pandas.Then we can find the values by using a particular index values.
Example-1
import pandas as pd import numpy as np a = np.array([ "c", "r", "a", "z", "y"]) n = pd.Series(a,index = [ 10, 11, 12, 13, 14]) print(n) print(n[10])
Output
10 c 11 r 12 a 13 z 14 y dtype: object c
Example-2
import pandas as pd import numpy as np a = np.array([ "c", "o", "d", "i", "n", "g"]) n = pd.Series(a,index = [ 10, 11, 12, 13, 14, 15]) print(n) print(n[12])
Output
10 c 11 o 12 d 13 i 14 n 15 g dtype: object d