bigframes.pandas.DataFrame.insert#
- DataFrame.insert(loc: int, column: blocks.Label, value: SingleItemValue, allow_duplicates: bool = False)[source]#
Insert column into DataFrame at specified location.
Examples:
>>> df = bpd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
Insert a new column named βcol3β between βcol1β and βcol2β with all entries set to 5.
>>> df.insert(1, 'col3', 5) >>> df col1 col3 col2 0 1 5 3 1 2 5 4 [2 rows x 3 columns]
Insert another column named βcol2β at the beginning of the DataFrame with values [5, 6]
>>> df.insert(0, 'col2', [5, 6], allow_duplicates=True) >>> df col2 col1 col3 col2 0 5 1 5 3 1 6 2 5 4 [2 rows x 4 columns]
- Parameters:
loc (int) β Insertion index. Must verify 0 <= loc <= len(columns).
column (str, number, or hashable object) β Label of the inserted column.
value (Scalar, Series, or array-like) β Content of the inserted column.
allow_duplicates (bool, default False) β Allow duplicate column labels to be created.
- Raises:
IndexError β If
columnindex is out of bounds with the total count of columns.ValueError β If
columnis already contained in the DataFrame, unlessallow_duplicatesis set to True.