pandas.DataFrame.isetitem#

DataFrame.isetitem(loc, value)[source]#

Set the given value in the column(s) with position loc.

This is a positional analogue to __setitem__.

Parameters:
locint, slice, or array-like of ints or bools

Index position(s) for the column(s).

valuescalar or arraylike

Value(s) for the column(s). When loc selects several positions, a scalar fills each of them and an arraylike must have one column per position.

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 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.

Examples

>>> df = pd.DataFrame({"A": [1, 2], "B": [3, 4]})
>>> df.isetitem(1, [5, 6])
>>> df
      A  B
0     1  5
1     2  6