 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements
 