Skip to content

Commit d4f7ae4

Browse files
committed
DOC: add examples to insert and update generally
This commit mainly adds examples on usage. This commit also fills in information suggested by `validate_docstrings.py` script.
1 parent 55e3bff commit d4f7ae4

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

pandas/core/frame.py

+26
Original file line numberDiff line numberDiff line change
@@ -3741,6 +3741,8 @@ def insert(self, loc, column, value, allow_duplicates=False) -> None:
37413741
"""
37423742
Insert column into DataFrame at specified location.
37433743
3744+
Performs column insertion in-place.
3745+
37443746
Raises a ValueError if `column` is already contained in the DataFrame,
37453747
unless `allow_duplicates` is set to True.
37463748
@@ -3751,7 +3753,31 @@ def insert(self, loc, column, value, allow_duplicates=False) -> None:
37513753
column : str, number, or hashable object
37523754
Label of the inserted column.
37533755
value : int, Series, or array-like
3756+
Input data to be inserted.
37543757
allow_duplicates : bool, optional
3758+
Whether to allow duplicate column label names.
3759+
3760+
See Also
3761+
--------
3762+
Index.insert : Insert new item by index.
3763+
3764+
Examples
3765+
--------
3766+
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
3767+
>>> df
3768+
col1 col2
3769+
0 1 3
3770+
1 2 4
3771+
>>> df.insert(1, "newcol", [99, 99])
3772+
>>> df
3773+
col1 newcol col2
3774+
0 1 99 3
3775+
1 2 99 4
3776+
>>> df.insert(0, "col1", [100, 100], allow_duplicates=True)
3777+
>>> df
3778+
col1 col1 newcol col2
3779+
0 100 1 99 3
3780+
1 100 2 99 4
37553781
"""
37563782
if allow_duplicates and not self.flags.allows_duplicate_labels:
37573783
raise ValueError(

0 commit comments

Comments
 (0)