pandas.DataFrame.isetitem#

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

Set the given value in the column with position loc.

This is a positional analogue to __setitem__.

Parameters:
locint or sequence of ints

Index position for the column.

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