From dae178101a4ce5b2bcc6da8c640bd53cb3dcb7b5 Mon Sep 17 00:00:00 2001 From: Zhengbo Wang <77875500+luke396@users.noreply.github.com> Date: Wed, 28 Feb 2024 00:52:07 +0800 Subject: [PATCH] DOC: Add `DataFrame.isetitem` method (#57614) * Add DataFrame.isetitem method * Add See-Also and Examples * Fix orfer * Update pandas/core/frame.py Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> --------- Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> --- doc/source/reference/frame.rst | 1 + pandas/core/frame.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/doc/source/reference/frame.rst b/doc/source/reference/frame.rst index 31a1c6008bce8..7680c8b434866 100644 --- a/doc/source/reference/frame.rst +++ b/doc/source/reference/frame.rst @@ -74,6 +74,7 @@ Indexing, iteration DataFrame.where DataFrame.mask DataFrame.query + DataFrame.isetitem For more information on ``.at``, ``.iat``, ``.loc``, and ``.iloc``, see the :ref:`indexing documentation `. diff --git a/pandas/core/frame.py b/pandas/core/frame.py index e5d424b15e69e..f530466c0fc30 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -4018,6 +4018,11 @@ def isetitem(self, loc, value) -> None: value : scalar or arraylike Value(s) for the column. + See Also + -------- + DataFrame.iloc : Purely integer-location based indexing for selection by + position. + Notes ----- ``frame.isetitem(loc, value)`` is an in-place method as it will @@ -4028,6 +4033,15 @@ def isetitem(self, loc, value) -> None: In cases where ``frame.columns`` is unique, this is equivalent to ``frame[frame.columns[i]] = value``. + + Examples + -------- + >>> df = pd.DataFrame({"A": [1, 2], "B": [3, 4]}) + >>> df.isetitem(1, [5, 6]) + >>> df + A B + 0 1 5 + 1 2 6 """ if isinstance(value, DataFrame): if is_integer(loc):