Skip to content

Commit d3e970b

Browse files
authored
DOC: add examples to insert and update generally (#37690)
* 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. * DOC: remove inferred insert parameter descriptions
1 parent 3556865 commit d3e970b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pandas/core/frame.py

+22
Original file line numberDiff line numberDiff line change
@@ -3747,6 +3747,28 @@ def insert(self, loc, column, value, allow_duplicates=False) -> None:
37473747
Label of the inserted column.
37483748
value : int, Series, or array-like
37493749
allow_duplicates : bool, optional
3750+
3751+
See Also
3752+
--------
3753+
Index.insert : Insert new item by index.
3754+
3755+
Examples
3756+
--------
3757+
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
3758+
>>> df
3759+
col1 col2
3760+
0 1 3
3761+
1 2 4
3762+
>>> df.insert(1, "newcol", [99, 99])
3763+
>>> df
3764+
col1 newcol col2
3765+
0 1 99 3
3766+
1 2 99 4
3767+
>>> df.insert(0, "col1", [100, 100], allow_duplicates=True)
3768+
>>> df
3769+
col1 col1 newcol col2
3770+
0 100 1 99 3
3771+
1 100 2 99 4
37503772
"""
37513773
if allow_duplicates and not self.flags.allows_duplicate_labels:
37523774
raise ValueError(

0 commit comments

Comments
 (0)