From 06230039e02e6cb1e4017488ef837ff292948e51 Mon Sep 17 00:00:00 2001 From: Aaron Kosel Date: Sun, 11 Mar 2018 19:26:33 -0500 Subject: [PATCH 1/4] DOC: update the DataFrame.at[] docstring --- pandas/core/indexing.py | 44 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 560e7638b5510..d6efdd7c0a254 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -1888,11 +1888,49 @@ def __setitem__(self, key, value): class _AtIndexer(_ScalarAccessIndexer): - """Fast label-based scalar accessor + """ + Access a single value for a row/column label pair. - Similarly to ``loc``, ``at`` provides **label** based scalar lookups. - You can also set using these indexers. + Similar to ``loc``, in that both provide label-based lookups. Use + ``at`` if you only need to get or set a single value in a DataFrame + or Series. + See Also + -------- + DataFrame.iat : Access a single value for a row/column pair by integer position + DataFrame.loc : Access a group of rows and columns by label(s) + Series.at : Access a single value using a label + + Examples + -------- + >>> df = pd.DataFrame([[0, 2, 3], [0, 4, 1], [10, 20, 30]], + ... index=[4, 5, 6], columns=['A', 'B', 'C']) + >>> df + A B C + 4 0 2 3 + 5 0 4 1 + 6 10 20 30 + + Get value at specified row/column pair + + >>> df.at[4, 'B'] + 2 + + Set value at specified row/column pair + + >>> df.at[4, 'B'] = 10 + >>> df.at[4, 'B'] + 10 + + Get value within a series + + >>> df.loc[5].at['B'] + 4 + + Raises + ------ + KeyError + When label does not exist in DataFrame """ _takeable = False From 1434a3b0ec257bc3c2628417158a5b9ff9265f89 Mon Sep 17 00:00:00 2001 From: Aaron Kosel Date: Sun, 11 Mar 2018 19:27:58 -0500 Subject: [PATCH 2/4] Fix line length --- pandas/core/indexing.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index d6efdd7c0a254..89660a991e56e 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -1897,9 +1897,12 @@ class _AtIndexer(_ScalarAccessIndexer): See Also -------- - DataFrame.iat : Access a single value for a row/column pair by integer position - DataFrame.loc : Access a group of rows and columns by label(s) - Series.at : Access a single value using a label + DataFrame.iat + Access a single value for a row/column pair by integer position + DataFrame.loc + Access a group of rows and columns by label(s) + Series.at + Access a single value using a label Examples -------- From 161e0873b6c643e74dc9440d6fa70934df8e82b5 Mon Sep 17 00:00:00 2001 From: Aaron Kosel Date: Mon, 12 Mar 2018 08:16:58 -0500 Subject: [PATCH 3/4] Update based on comments --- pandas/core/indexing.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 89660a991e56e..4c56b02ef5c32 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -1897,12 +1897,10 @@ class _AtIndexer(_ScalarAccessIndexer): See Also -------- - DataFrame.iat - Access a single value for a row/column pair by integer position - DataFrame.loc - Access a group of rows and columns by label(s) - Series.at - Access a single value using a label + DataFrame.iat : Access a single value for a row/column pair by integer + position + DataFrame.loc : Access a group of rows and columns by label(s) + Series.at : Access a single value using a label Examples -------- @@ -1925,7 +1923,7 @@ class _AtIndexer(_ScalarAccessIndexer): >>> df.at[4, 'B'] 10 - Get value within a series + Get value within a Series >>> df.loc[5].at['B'] 4 From d3f78b47ba554c74d2fe6d5391390c65d67802da Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Mon, 12 Mar 2018 14:19:21 +0100 Subject: [PATCH 4/4] Update indexing.py --- 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 4c56b02ef5c32..fb3279840c7bf 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -1898,7 +1898,7 @@ class _AtIndexer(_ScalarAccessIndexer): See Also -------- DataFrame.iat : Access a single value for a row/column pair by integer - position + position DataFrame.loc : Access a group of rows and columns by label(s) Series.at : Access a single value using a label