Skip to content

Commit 8d2a4e1

Browse files
DOC: clarify "inplace"-ness of DataFrame.setitem (#51328)
1 parent 9a71cdb commit 8d2a4e1

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

pandas/core/frame.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -3870,23 +3870,27 @@ def _get_value(self, index, col, takeable: bool = False) -> Scalar:
38703870

38713871
def isetitem(self, loc, value) -> None:
38723872
"""
3873-
Set the given value in the column with position 'loc'.
3873+
Set the given value in the column with position `loc`.
38743874
3875-
This is a positional analogue to __setitem__.
3875+
This is a positional analogue to ``__setitem__``.
38763876
38773877
Parameters
38783878
----------
38793879
loc : int or sequence of ints
3880+
Index position for the column.
38803881
value : scalar or arraylike
3882+
Value(s) for the column.
38813883
38823884
Notes
38833885
-----
3884-
Unlike `frame.iloc[:, i] = value`, `frame.isetitem(loc, value)` will
3885-
_never_ try to set the values in place, but will always insert a new
3886-
array.
3887-
3888-
In cases where `frame.columns` is unique, this is equivalent to
3889-
`frame[frame.columns[i]] = value`.
3886+
``frame.isetitem(loc, value)`` is an in-place method as it will
3887+
modify the DataFrame in place (not returning a new object). In contrast to
3888+
``frame.iloc[:, i] = value`` which will try to update the existing values in
3889+
place, ``frame.isetitem(loc, value)`` will not update the values of the column
3890+
itself in place, it will instead insert a new array.
3891+
3892+
In cases where ``frame.columns`` is unique, this is equivalent to
3893+
``frame[frame.columns[i]] = value``.
38903894
"""
38913895
if isinstance(value, DataFrame):
38923896
if is_scalar(loc):

0 commit comments

Comments
 (0)