Pandas iat Example in Python with various Examples

Pandas iat Example in Python with various Examples

Pandas is a very popular python package for data manipulation. There are many functions in it that allow you to read, write, append, join dataframe e.t.c. Pandas iat [] is one of them. It allows in getting a single value of the data in a specific location. In this entire tutorial  you will know how to implement it with examples.

Syntax of the Pandas iat []

The syntax of the Pandas iat is below.

pandas.DataFrame.iat[your_row,your_column]

your_row: It is the position of the element in the row.

your_column: The position of the element in the column.

The method return single value from the specified location.

Examples on Pandas iat []

In this section, you will know the various examples of pandas iat[] method.

But before that lets create a sample dataframe where you will use this method.

Creation of Sample Dataframe

You can use your know data frame, excel, CSV files e.t.c. But Here I am creating a simple dataframe for more understanding.

You can create datafrme using pd.DataFrame()method. Let’s create it.

df = pd.DataFrame([[10, 20, 30], [40, 50,60], [70, 80, 90]],
                  columns=['A', 'B', 'C'])

Output

Sample Dataframe for pandas iat method implementation
Sample Dataframe for pandas iat method implementation

Now let’s implement the example.

Example 1: Accessing a specific element

Suppose I want to get the element 50 then I have to execute the following lines of code.

df.iat[1, 1]

Output

Getting the 50 element using the iat() method
Getting the 50 element using the iat() method

In the same way you can get the other elements of the dataframe.

Example 2: Change the element of a specific position

The above example was for accessing the element. Let’s change the value of the second row and the third column. Execute the below lines of code.

df.iat[1, 2] = 100
print(df)

Now if you print the data frame then you will get the datataframe with the changed value.

Output

Changing the value of element using iat method
Changing the value of element using iat method

END NOTES

These are examples of how to use the Pandas iat[] method. Some readers have asked me about the difference between the iat[] and iloc[]. The answer is that iat[] returns only a single value but the iloc[] returns more than one value. I hope you have liked this tutorial. If you have any queries then you can contact us for more help.

Source

Pandas pandas.DataFrame.iat documentation

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

Meet Sukesh ( Chief Editor ), a passionate and skilled Python programmer with a deep fascination for data science, NumPy, and Pandas. His journey in the world of coding began as a curious explorer and has evolved into a seasoned data enthusiast.
 
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner