@@ -3677,6 +3677,8 @@ def insert(self, loc, column, value, allow_duplicates=False) -> None:
3677
3677
"""
3678
3678
Insert column into DataFrame at specified location.
3679
3679
3680
+ Performs column insertion in-place.
3681
+
3680
3682
Raises a ValueError if `column` is already contained in the DataFrame,
3681
3683
unless `allow_duplicates` is set to True.
3682
3684
@@ -3687,7 +3689,31 @@ def insert(self, loc, column, value, allow_duplicates=False) -> None:
3687
3689
column : str, number, or hashable object
3688
3690
Label of the inserted column.
3689
3691
value : int, Series, or array-like
3692
+ Input data to be inserted.
3690
3693
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
3691
3717
"""
3692
3718
if allow_duplicates and not self .flags .allows_duplicate_labels :
3693
3719
raise ValueError (
0 commit comments