Pandas Series - iat[] property
The Pandas iat[] property is used to access a single value for a row/column pair by integer position.
Exceptions
Raises IndexError if integer position is out of bounds.
Example: Indexing element of a DataFrame
In the example below, a DataFrame df is created. The iat[] is used to get and set the elements of this DataFrame.
import pandas as pd import numpy as np df = pd.DataFrame({ "Salary": [25, 24, 30, 28], "Bonus": [10, 8, 9, np.nan], "Others": [5, 4, 7, 5]}, index= ["2015", "2016", "2017", "2018"] ) print("The DataFrame is:") print(df) #getting value at specified location print("\ndf.iat[1, 1] returns:") print(df.iat[1, 1]) #setting value at specified location df.iat[0, 0] = 100 #after modification print("\nThe DataFrame is:") print(df)
The output of the above code will be:
The DataFrame is: Salary Bonus Others 2015 25 10.0 5 2016 24 8.0 4 2017 30 9.0 7 2018 28 NaN 5 df.iat[1, 1] returns: 8.0 The DataFrame is: Salary Bonus Others 2015 100 10.0 5 2016 24 8.0 4 2017 30 9.0 7 2018 28 NaN 5
Example: Indexing element of a Series
The iat[] can be used to get the elements of a Series as well. Consider the example below:
import pandas as pd import numpy as np df = pd.DataFrame({ "Salary": [25, 24, 30, 28], "Bonus": [10, 8, 9, np.nan], "Others": [5, 4, 7, 5]}, index= ["2015", "2016", "2017", "2018"] ) print("The DataFrame is:") print(df) #getting value of second element of the given series print("\ndf.iloc[1].iat[1] returns:") print(df.iloc[1].iat[1])
The output of the above code will be:
The DataFrame is: Salary Bonus Others 2015 25 10.0 5 2016 24 8.0 4 2017 30 9.0 7 2018 28 NaN 5 df.iloc[1].iat[1] returns: 8.0
❮ Pandas Series - Functions