Pandas Series property: iat
Access a single value for a row/column pair in Pandas
The iat property is used to access a single value for a row/column pair by integer position.
Similar to iloc, in that both provide integer-based lookups. Use iat if you only need to get or set a single value in a DataFrame or Series.
Syntax:
Series.iat
Raises: IndexError
When integer position is out of bounds
Example:
Python-Pandas Code:
import numpy as np
import pandas as pd
df = pd.DataFrame([[2, 3, 4], [0, 5, 6], [20, 30, 40]],
columns=['P', 'Q', 'R'])
df
Output:
P Q R 0 2 3 4 1 0 5 6 2 20 30 40
Example - Get value at specified row/column pair:
Python-Pandas Code:
import numpy as np
import pandas as pd
df = pd.DataFrame([[2, 3, 4], [0, 5, 6], [20, 30, 40]],
columns=['P', 'Q', 'R'])
df.iat[2, 2]
Output:
40
Example - Set value at specified row/column pair:
Python-Pandas Code:
import numpy as np
import pandas as pd
df = pd.DataFrame([[2, 3, 4], [0, 5, 6], [20, 30, 40]],
columns=['P', 'Q', 'R'])
df.iat[2, 2] = 10
df.iat[2, 2]
Output:
10
Example - Get value within a series:
Python-Pandas Code:
import numpy as np
import pandas as pd
df = pd.DataFrame([[2, 3, 4], [0, 5, 6], [20, 30, 40]],
columns=['P', 'Q', 'R'])
df.iat[2, 2] = 10
df.loc[0].iat[2]
Output:
4
Previous: Access a single value for a row/column label pair in Pandas
Next: Access a group of rows and columns in Pandas
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/pandas/series/series-iat.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics