Skip to content

DOC: clarify "inplace"-ness of DataFrame.setitem #51328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3869,23 +3869,27 @@ def _get_value(self, index, col, takeable: bool = False) -> Scalar:

def isetitem(self, loc, value) -> None:
"""
Set the given value in the column with position 'loc'.
Set the given value in the column with position `loc`.

This is a positional analogue to __setitem__.
This is a positional analogue to ``__setitem__``.

Parameters
----------
loc : int or sequence of ints
Index position for the column.
value : scalar or arraylike
Value(s) for the column.

Notes
-----
Unlike `frame.iloc[:, i] = value`, `frame.isetitem(loc, value)` will
_never_ try to set the values in place, but will always insert a new
array.

In cases where `frame.columns` is unique, this is equivalent to
`frame[frame.columns[i]] = value`.
``frame.isetitem(loc, value)`` is an in-place method as it will
modify the DataFrame in place (not returning a new object). In contrast to
``frame.iloc[:, i] = value`` which will try to update the existing values in
place, ``frame.isetitem(loc, value)`` will not update the values of the column
itself in place, it will instead insert a new array.

In cases where ``frame.columns`` is unique, this is equivalent to
``frame[frame.columns[i]] = value``.
"""
if isinstance(value, DataFrame):
if is_scalar(loc):
Expand Down