pandas.DataFrame.isetitem — pandas 3.0.0rc0+33.g1fd184de2a documentation (original) (raw)
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
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 toframe.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 toframe[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