From d4f7ae44d73396892a981440c59b9054a9833bc3 Mon Sep 17 00:00:00 2001 From: Eric Leung Date: Sat, 7 Nov 2020 14:54:09 -0800 Subject: [PATCH 1/2] 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. --- pandas/core/frame.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index f710660d6ad8e..cf0828a7b0405 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3741,6 +3741,8 @@ def insert(self, loc, column, value, allow_duplicates=False) -> None: """ Insert column into DataFrame at specified location. + Performs column insertion in-place. + Raises a ValueError if `column` is already contained in the DataFrame, unless `allow_duplicates` is set to True. @@ -3751,7 +3753,31 @@ def insert(self, loc, column, value, allow_duplicates=False) -> None: column : str, number, or hashable object Label of the inserted column. value : int, Series, or array-like + Input data to be inserted. allow_duplicates : bool, optional + Whether to allow duplicate column label names. + + See Also + -------- + Index.insert : Insert new item by index. + + Examples + -------- + >>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]}) + >>> df + col1 col2 + 0 1 3 + 1 2 4 + >>> df.insert(1, "newcol", [99, 99]) + >>> df + col1 newcol col2 + 0 1 99 3 + 1 2 99 4 + >>> df.insert(0, "col1", [100, 100], allow_duplicates=True) + >>> df + col1 col1 newcol col2 + 0 100 1 99 3 + 1 100 2 99 4 """ if allow_duplicates and not self.flags.allows_duplicate_labels: raise ValueError( From 4ec6e21d19970851981ec02651917afaf26a6423 Mon Sep 17 00:00:00 2001 From: Eric Leung Date: Sun, 8 Nov 2020 08:12:27 -0800 Subject: [PATCH 2/2] DOC: remove inferred insert parameter descriptions --- pandas/core/frame.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index cf0828a7b0405..2f5736be8f604 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3741,8 +3741,6 @@ def insert(self, loc, column, value, allow_duplicates=False) -> None: """ Insert column into DataFrame at specified location. - Performs column insertion in-place. - Raises a ValueError if `column` is already contained in the DataFrame, unless `allow_duplicates` is set to True. @@ -3753,9 +3751,7 @@ def insert(self, loc, column, value, allow_duplicates=False) -> None: column : str, number, or hashable object Label of the inserted column. value : int, Series, or array-like - Input data to be inserted. allow_duplicates : bool, optional - Whether to allow duplicate column label names. See Also --------