Skip to content

Commit d5a4629

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 a70144e commit d5a4629

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
@@ -3677,6 +3677,8 @@ def insert(self, loc, column, value, allow_duplicates=False) -> None:
36773677
"""
36783678
Insert column into DataFrame at specified location.
36793679
3680+
Performs column insertion in-place.
3681+
36803682
Raises a ValueError if `column` is already contained in the DataFrame,
36813683
unless `allow_duplicates` is set to True.
36823684
@@ -3687,7 +3689,31 @@ def insert(self, loc, column, value, allow_duplicates=False) -> None:
36873689
column : str, number, or hashable object
36883690
Label of the inserted column.
36893691
value : int, Series, or array-like
3692+
Input data to be inserted.
36903693
allow_duplicates : bool, optional
3694+
Whether to allow duplicate column label names.
3695+
3696+
See Also
3697+
--------
3698+
Index.insert : Insert new item by index.
3699+
3700+
Examples
3701+
--------
3702+
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
3703+
>>> df
3704+
col1 col2
3705+
0 1 3
3706+
1 2 4
3707+
>>> df.insert(1, "newcol", [99, 99])
3708+
>>> df
3709+
col1 newcol col2
3710+
0 1 99 3
3711+
1 2 99 4
3712+
>>> df.insert(0, "col1", [100, 100], allow_duplicates=True)
3713+
>>> df
3714+
col1 col1 newcol col2
3715+
0 100 1 99 3
3716+
1 100 2 99 4
36913717
"""
36923718
if allow_duplicates and not self.flags.allows_duplicate_labels:
36933719
raise ValueError(

0 commit comments

Comments
 (0)