@@ -3741,6 +3741,8 @@ def insert(self, loc, column, value, allow_duplicates=False) -> None:
3741
3741
"""
3742
3742
Insert column into DataFrame at specified location.
3743
3743
3744
+ Performs column insertion in-place.
3745
+
3744
3746
Raises a ValueError if `column` is already contained in the DataFrame,
3745
3747
unless `allow_duplicates` is set to True.
3746
3748
@@ -3751,7 +3753,31 @@ def insert(self, loc, column, value, allow_duplicates=False) -> None:
3751
3753
column : str, number, or hashable object
3752
3754
Label of the inserted column.
3753
3755
value : int, Series, or array-like
3756
+ Input data to be inserted.
3754
3757
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
3755
3781
"""
3756
3782
if allow_duplicates and not self .flags .allows_duplicate_labels :
3757
3783
raise ValueError (
0 commit comments