- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to access a single value in pandas DataFrame using the integer positions?
The pandas.DataFrame.iat attribute is used to access a single value of the DataFrame using the row/column integer positions and It is very similar to the iloc in pandas instead of accessing a group of elements here we will access a single element.
The “iat” attribute takes the integer index values of both rows and columns for getting or setting the element in a particular place.
The attribute will raise an “IndexError” if the given integer position is out of bounds.
Example 1
In this following example, we have created a DataFrame, accessing the 2nd-row 1st column element by using the iat attribute.
# importing pandas package import pandas as pd # create a Pandas DataFrame df = pd.DataFrame({'A':[1, 'u', 60], 'B':[12.2, 17.4, 34.34], 'C':list('XYZ')}) print("DataFrame:") print(df) # get a value using integer position result = df.iat[1, 0] print("Output:") print(result)
Output
The output is given below −
DataFrame: A B C 0 1 12.20 X 1 u 17.40 Y 2 60 34.34 Z Output: u
We have successfully accessed the 2nd-row 1st column element by specifying 1, 0 to the iat attribute.
Example 2
Now, let’s update the value “50” at the 2nd-row 1st column using the “iat” attribute.
# importing pandas package import pandas as pd # create a Pandas DataFrame df = pd.DataFrame({'A':[1, 'u', 60], 'B':[12.2, 17.4, 34.34], 'C':list('XYZ')}) print("DataFrame:") print(df) # set a value df.iat[1, 0] = 50 print("Updated DataFrame:") print(df)
Output
The output is as follows −
DataFrame: A B C 0 1 12.20 X 1 u 17.40 Y 2 60 34.34 Z Updated DataFrame: A B C 0 1 12.20 X 1 50 17.40 Y 2 60 34.34 Z
We successfully updated the value “50” at integer index position “1, 0” by using the “.iat” property of the pandas.DataFrame; we can observe both the DataFrame objects in the above output block.
- Related Articles
- How to access a single value in pandas Series using the integer position?
- How to access a single value in pandas Series using the .at attribute?
- How to access a single value in pandas Data Frame using the .at attribute?
- How to access pandas DataFrame elements using the .iloc attribute?
- How to access pandas DataFrame elements using the .loc attribute?
- How to access a group of rows in a Pandas DataFrame?
- How to Merge multiple CSV Files into a single Pandas dataframe ?
- Python Pandas - How to select rows from a DataFrame by integer location
- How to Merge all CSV Files into a single dataframe – Python Pandas?
- Pandas series Vs. single-column DataFrame
- How to get a value from the cell of a Pandas DataFrame?
- How to create a pandas DataFrame using a list?
- How to create a pandas DataFrame using a dictionary?
- How to convert a single character to its integer value in Python?
- How to check if any value is NaN in a Pandas DataFrame?
