Pandas Series is a one-dimensional labeled array capable of holding data of any type (integer, string, float, python objects, etc.). Labels need not be unique but must be a hashable type.
Let’s discuss different ways to access the elements of given Pandas Series.
First create a Pandas Series.
import pandas as pd
ser = pd.Series(df[ 'Name' ])
ser.head( 10 )
|
Output:

Example #1: Get the first element of series
import pandas as pd
df[ 'Name' ].head( 10 )
ser[ 0 ]
|
Output:

Example #2: Access multiple elements by providing position of item
import pandas as pd
df[ 'Name' ].head( 10 )
ser[[ 0 , 3 , 6 , 9 ]]
|
Output:

Example #3: Access first 5 elements in Series
import pandas as pd
df[ 'Name' ].head( 10 )
ser[: 5 ]
|
Output:

Example #4: Get last 10 elements in Series
import pandas as pd
df[ 'Name' ].head( 10 )
ser[ - 10 :]
|
Output:

Example #5: Access multiple elements by providing label of index
import pandas as pd
import numpy as np
ser = pd.Series(np.arange( 3 , 15 ), index = list ( "abcdefghijkl" ))
ser[[ 'a' , 'd' , 'g' , 'l' ]]
|
Output:

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
06 Dec, 2018
Like Article
Save Article