MCPcopy
hub / github.com/pandas-dev/pandas / isetitem

Method isetitem

pandas/core/frame.py:4503–4557  ·  view source on GitHub ↗

Set the given value in the column with position `loc`. 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)

(self, loc, value)

Source from the content-addressed store, hash-verified

4501 return series._values[loc]
4502
4503 def isetitem(self, loc, value) -> None:
4504 """
4505 Set the given value in the column with position `loc`.
4506
4507 This is a positional analogue to ``__setitem__``.
4508
4509 Parameters
4510 ----------
4511 loc : int or sequence of ints
4512 Index position for the column.
4513 value : scalar or arraylike
4514 Value(s) for the column.
4515
4516 See Also
4517 --------
4518 DataFrame.iloc : Purely integer-location based indexing for selection by
4519 position.
4520
4521 Notes
4522 -----
4523 ``frame.isetitem(loc, value)`` is an in-place method as it will
4524 modify the DataFrame in place (not returning a new object). In contrast to
4525 ``frame.iloc[:, i] = value`` which will try to update the existing values in
4526 place, ``frame.isetitem(loc, value)`` will not update the values of the column
4527 itself in place, it will instead insert a new array.
4528
4529 In cases where ``frame.columns`` is unique, this is equivalent to
4530 ``frame[frame.columns[i]] = value``.
4531
4532 Examples
4533 --------
4534 >>> df = pd.DataFrame({"A": [1, 2], "B": [3, 4]})
4535 >>> df.isetitem(1, [5, 6])
4536 >>> df
4537 A B
4538 0 1 5
4539 1 2 6
4540 """
4541 if isinstance(value, DataFrame):
4542 if is_integer(loc):
4543 loc = [loc]
4544
4545 if len(loc) != len(value.columns):
4546 raise ValueError(
4547 f"Got {len(loc)} positions but value has {len(value.columns)} "
4548 f"columns."
4549 )
4550
4551 for i, idx in enumerate(loc):
4552 arraylike, refs = self._sanitize_column(value.iloc[:, i])
4553 self._iset_item_mgr(idx, arraylike, inplace=False, refs=refs)
4554 return
4555
4556 arraylike, refs = self._sanitize_column(value)
4557 self._iset_item_mgr(loc, arraylike, inplace=False, refs=refs)
4558
4559 def __setitem__(self, key, value) -> None:
4560 """

Callers 15

_set_item_frame_valueMethod · 0.95
readMethod · 0.95
test_isetitem_ea_dfMethod · 0.95
test_isetitem_seriesFunction · 0.95
test_isetitem_frameFunction · 0.95
fillnaMethod · 0.80

Calls 2

_sanitize_columnMethod · 0.95
_iset_item_mgrMethod · 0.95