From 011906e7731cfd0a697164a0531d1a40701f1366 Mon Sep 17 00:00:00 2001 From: nofarmishraki Date: Sun, 31 Jan 2021 15:51:37 +0200 Subject: [PATCH 1/3] DOC: add example to insert (#39313) --- pandas/core/frame.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 82e984d36b6a1..7ceebb52bdb6e 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3870,6 +3870,13 @@ def insert(self, loc, column, value, allow_duplicates: bool = False) -> None: col1 col1 newcol col2 0 100 1 99 3 1 100 2 99 4 + + Notice that Pandas uses index alignment in case of `value` from type `Series`: + >>> df.insert(0, "col0", pd.Series([5, 6], index=[1, 2])) + >>> df + col0 col1 col1 newcol col2 + 0 NaN 100 1 99 3 + 1 5.0 100 2 99 4 """ if allow_duplicates and not self.flags.allows_duplicate_labels: raise ValueError( From 9e95c0946049b829b242b96015ed92943650ca41 Mon Sep 17 00:00:00 2001 From: nofarmishraki Date: Sun, 31 Jan 2021 19:40:36 +0200 Subject: [PATCH 2/3] DOC: fix style (#39313) --- pandas/core/frame.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 7ceebb52bdb6e..6be7c02fc7571 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3872,6 +3872,7 @@ def insert(self, loc, column, value, allow_duplicates: bool = False) -> None: 1 100 2 99 4 Notice that Pandas uses index alignment in case of `value` from type `Series`: + >>> df.insert(0, "col0", pd.Series([5, 6], index=[1, 2])) >>> df col0 col1 col1 newcol col2 From 711ed22fd39be85abaf2cb9299135124139af007 Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Mon, 1 Feb 2021 19:08:07 +0000 Subject: [PATCH 3/3] Update pandas/core/frame.py --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 6be7c02fc7571..7bcc6523bb2be 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3871,7 +3871,7 @@ def insert(self, loc, column, value, allow_duplicates: bool = False) -> None: 0 100 1 99 3 1 100 2 99 4 - Notice that Pandas uses index alignment in case of `value` from type `Series`: + Notice that pandas uses index alignment in case of `value` from type `Series`: >>> df.insert(0, "col0", pd.Series([5, 6], index=[1, 2])) >>> df