
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python - How to access the last element in a Pandas series?
We will be using the iat attribute to access the last element, since it is used to access a single value for a row/column pair by integer position.
Let us first import the required Pandas library −
import pandas as pd
Create a Pandas series with numbers −
data = pd.Series([10, 20, 5, 65, 75, 85, 30, 100])
Now, get the last element using iat() −
data.iat[-1]
Example
Following is the code −
import pandas as pd # pandas series data = pd.Series([10, 20, 5, 65, 75, 85, 30, 100]) print"Series...\n",data # get the first element print"The first element in the series = ", data.iat[0] # get the last element print"The last element in the series = ", data.iat[-1]
Output
This will produce the following output −
Series... 0 10 1 20 2 5 3 65 4 75 5 85 6 30 7 100 dtype: int64 The first element in the series = 10 The last element in the series = 100
- Related Articles
- How to access datetime indexed elements in pandas series?
- How to access pandas Series elements using the .iloc attribute?
- How to access pandas Series elements using the .loc attribute?
- How to access a single value in pandas Series using the .at attribute?
- How to access a single value in pandas Series using the integer position?
- How to access Pandas Series elements by using indexing?
- How to append a pandas Series object to another Series in Python?
- Python - Repeat each element of a Pandas Series in a dissimilar way
- How to check file last access time using Python?
- How to get the last element of a list in Python?
- How to remove the last element from a set in Python?
- How to retrieve the last valid index from a series object using pandas series.last_valid_index() method?
- How to access the last value in a vector in R?
- How to create a Pandas series from a python dictionary?
- How to access a group of elements from pandas Series using the .iloc attribute with slicing object?

Advertisements