How to access the last element in a Pandas series? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Prerequisite: Pandas Pandas series is useful in handling various analytical operations independently or as being a part of pandas data frame. So it is important for us to know how various operations are performed in pandas series. The following article discusses various ways in which last element of a pandas series can be retrieved. Method 1: Naive approach There are two naive approaches for accessing the last element: Iterate through the entire series till we reach the end.Find the length of the series. The last element would be length-1 (as indexing starts from 0). Program: Python3 # importing the pandas library import pandas as pd # initializing the series ser = pd.Series(['g', 'e', 'e', 'k', 's']) # iterating the series until the iterator reaches the end of the series for i in range(0, ser.size): if i == ser.size-1: # printing the last element i.e, size of the series-1 print("The last element in the series using loop is : ", ser[i]) # calculating the length of the series len = ser.size # printing the last element i.e len-1 as indexing starts from 0 print("The last element in the series by calculating length is : ", ser[len-1]) Output: Method 2: Using .iloc or .iat Pandas iloc is used to retrieve data by specifying its integer index. In python negative index starts from end therefore we can access the last element by specifying index to -1 instead of length-1 which will yield the same result. Pandas iat is used to access data of a passed location. iat is comparatively faster than iloc. Also note that ser[-1] will not print the last element of series, as series supports positive indexes only. However, we can use negative indexing in iloc and iat. Program: Python3 # importing the pandas library and time import pandas as pd import time # initializing the series ser = pd.Series(['g', 'e', 'e', 'k', 's']) start = time.time() print("The last element in the series using iloc is : ", ser.iloc[-1]) end = time.time() print("Time taken by iloc : ", end-start) start = time.time() print("The last element in the series using iat is : ", ser.iat[-1]) end = time.time() print("Time taken by iat : ", end-start) Output: Method 3: Using tail(1).item() tail(n) is used to access bottom n rows from a series or a data frame and item() returns the element of the given series object as scalar. Program: Python3 # importing the pandas library import pandas as pd # initializing the series ser = pd.Series(['g', 'e', 'e', 'k', 's']) # printing the last element using tail print("The last element in the series using tail is : ", ser.tail(1).item()) Output: Comment More infoAdvertise with us Next Article Access the elements of a Series in Pandas D d2anubis Follow Improve Article Tags : Python Python-pandas Python pandas-series Python Pandas-exercise Practice Tags : python Similar Reads Access the elements of a Series in Pandas 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. Python 2 min read Accessing elements of a Pandas Series 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. An element in the series can be accessed similarly to that in an ndarray. Elements of a series can be accessed i 5 min read Accessing elements of a Pandas Series 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. An element in the series can be accessed similarly to that in an ndarray. Elements of a series can be accessed i 5 min read Accessing elements of a Pandas Series 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. An element in the series can be accessed similarly to that in an ndarray. Elements of a series can be accessed i 5 min read How to Reference the Next Row in a Pandas DataFrame To reference the next row in a Pandas DataFrame, you can use the .shift() method. This method shifts the data by a specified number of periods (rows), allowing you to access the previous or next row's values in a given column. It's useful for comparing consecutive rows or calculating differences bet 4 min read How to get nth row in a Pandas DataFrame? Pandas Dataframes are basically table format data that comprises rows and columns. Now for accessing the rows from large datasets, we have different methods like iloc, loc and values in Pandas. The most commonly used method is iloc(). Let us consider a simple example.Method 1. Using iloc() to access 4 min read Like