| [ Web Proxy ] |
| Viewing: https://dataframes.bigquery.dev/reference/api/bigframes.pandas.DataFrame.insert.html | [Back] [Original] |
Section Navigation
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]
IndexError If column index is out of bounds with the total count of columns.
ValueError If column is already contained in the DataFrame,
unless allow_duplicates is set to True.
Copyright 2019, Google.
Created using Sphinx 8.1.3.
Built with the PyData Sphinx Theme 0.19.0.
| Web Proxy Viewer | New URL | Original Page |