From 1a341307a8dc3a6ec94dab9e9d340b2f7b504967 Mon Sep 17 00:00:00 2001 From: Aaron Kosel Date: Sat, 10 Mar 2018 13:18:30 -0600 Subject: [PATCH 1/7] DOC: update the DataFrame.iat[] docstring --- pandas/core/indexing.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index ec2874b3bae95..9e0d7cd93fad2 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -1920,11 +1920,35 @@ def _convert_key(self, key, is_setter=False): class _iAtIndexer(_ScalarAccessIndexer): - """Fast integer location scalar accessor. + """ + Selects a single value for a row/column pair by integer position. - Similarly to ``iloc``, ``iat`` provides **integer** based lookups. - You can also set using these indexers. + Useful if performance is a major concern and you only need to + get or set a value at a particular row/column. + See Also + -------- + at : Selects a single value for a row/column label pair + loc : Selects a group of rows and columns by label(s) + iloc : Selects group of rows and columns by integer position(s) + + Returns + ------- + None + + Examples + -------- + >>> df = pd.DataFrame([[0,2,3], [0,4,1], [10,20,30]]) + >>> df + 0 1 2 + 0 0 2 3 + 1 0 4 1 + 2 10 20 30 + >>> df.iat[1, 2] + 1 + >>> df.iat[1, 2] = 10 + >>> df.iat[1, 2] + 10 """ _takeable = True From fa0edf7eab04ff9dd6145db335cafba333c88349 Mon Sep 17 00:00:00 2001 From: Aaron Kosel Date: Sat, 10 Mar 2018 15:08:31 -0600 Subject: [PATCH 2/7] Update based on PR comments --- pandas/core/indexing.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 9e0d7cd93fad2..c57cc2f0046d7 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -1932,13 +1932,9 @@ class _iAtIndexer(_ScalarAccessIndexer): loc : Selects a group of rows and columns by label(s) iloc : Selects group of rows and columns by integer position(s) - Returns - ------- - None - Examples -------- - >>> df = pd.DataFrame([[0,2,3], [0,4,1], [10,20,30]]) + >>> df = pd.DataFrame([[0, 2, 3], [0, 4, 1], [10, 20, 30]]) >>> df 0 1 2 0 0 2 3 From 2565642f125a1d399e935f86b489a9e4278265c1 Mon Sep 17 00:00:00 2001 From: Aaron Kosel Date: Sat, 10 Mar 2018 15:33:37 -0600 Subject: [PATCH 3/7] Update based on PR comments --- pandas/core/indexing.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index c57cc2f0046d7..750be07052652 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -1921,27 +1921,30 @@ def _convert_key(self, key, is_setter=False): class _iAtIndexer(_ScalarAccessIndexer): """ - Selects a single value for a row/column pair by integer position. + Access a single value for a row/column pair by integer position. - Useful if performance is a major concern and you only need to - get or set a value at a particular row/column. + Similar to ``iloc``, in that both provided integer-based lookups. Use + ``iat`` if you only need to get or set a single value in a DataFrame. See Also -------- - at : Selects a single value for a row/column label pair - loc : Selects a group of rows and columns by label(s) - iloc : Selects group of rows and columns by integer position(s) + DataFrame.at : Access a single value for a row/column label pair + DataFrame.loc : Access a group of rows and columns by label(s) + DataFrame.iloc : Access a group of rows and columns by integer position(s) Examples -------- - >>> df = pd.DataFrame([[0, 2, 3], [0, 4, 1], [10, 20, 30]]) + >>> df = pd.DataFrame([[0, 2, 3], [0, 4, 1], [10, 20, 30]], + ... columns=['A', 'B', 'C']) >>> df - 0 1 2 + A B C 0 0 2 3 1 0 4 1 2 10 20 30 + >>> df.iat[1, 2] 1 + >>> df.iat[1, 2] = 10 >>> df.iat[1, 2] 10 From e8233e515d851d00bbfcf38be96147959300f51d Mon Sep 17 00:00:00 2001 From: Aaron Kosel Date: Sat, 10 Mar 2018 15:34:47 -0600 Subject: [PATCH 4/7] Singular not plural --- pandas/core/indexing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 750be07052652..8f6c675d41a2b 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -1923,7 +1923,7 @@ class _iAtIndexer(_ScalarAccessIndexer): """ Access a single value for a row/column pair by integer position. - Similar to ``iloc``, in that both provided integer-based lookups. Use + 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. See Also From 88c23c0373335bc0faf82da092990e715c2d4cee Mon Sep 17 00:00:00 2001 From: Aaron Kosel Date: Sat, 10 Mar 2018 16:54:18 -0600 Subject: [PATCH 5/7] Update to account for use with Series. Add example using Series. --- pandas/core/indexing.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 8f6c675d41a2b..de1490e0ab107 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -1924,7 +1924,8 @@ class _iAtIndexer(_ScalarAccessIndexer): 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. + ``iat`` if you only need to get or set a single value in a ``DataFrame`` + or ``Series``. See Also -------- @@ -1942,12 +1943,26 @@ class _iAtIndexer(_ScalarAccessIndexer): 1 0 4 1 2 10 20 30 + Get value at specified row/column pair + >>> df.iat[1, 2] 1 + Set value at specified row/column pair + >>> df.iat[1, 2] = 10 >>> df.iat[1, 2] 10 + + Get value within a series + + >>> df.loc[0].iat[1] + 2 + + Raises + ------ + IndexError + When integer position is out of bounds """ _takeable = True From 6b1fc48e19e3a58d2d3c774e9dca244b9fdc6f49 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Sun, 11 Mar 2018 13:38:47 +0100 Subject: [PATCH 6/7] Update indexing.py --- pandas/core/indexing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index de1490e0ab107..4f7e302307602 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -1924,8 +1924,8 @@ class _iAtIndexer(_ScalarAccessIndexer): 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``. + ``iat`` if you only need to get or set a single value in a DataFrame + or Series. See Also -------- From aa387ad59a62562c94cce30a4737994b994a8396 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Sun, 11 Mar 2018 07:42:48 -0500 Subject: [PATCH 7/7] PEP8 --- pandas/core/indexing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 4f7e302307602..560e7638b5510 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -1936,7 +1936,7 @@ class _iAtIndexer(_ScalarAccessIndexer): Examples -------- >>> df = pd.DataFrame([[0, 2, 3], [0, 4, 1], [10, 20, 30]], - ... columns=['A', 'B', 'C']) + ... columns=['A', 'B', 'C']) >>> df A B C 0 0 2 3