Skip to content

Commit 3dfbf49

Browse files
nofarm3nofarmishMarcoGorelli
authored
DOC: add example to insert (#39313) (#39500)
* DOC: add example to insert (#39313) * DOC: fix style (#39313) * Update pandas/core/frame.py Co-authored-by: nofarmishraki <[email protected]> Co-authored-by: Marco Gorelli <[email protected]>
1 parent f037aca commit 3dfbf49

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pandas/core/frame.py

+8
Original file line numberDiff line numberDiff line change
@@ -3870,6 +3870,14 @@ def insert(self, loc, column, value, allow_duplicates: bool = False) -> None:
38703870
col1 col1 newcol col2
38713871
0 100 1 99 3
38723872
1 100 2 99 4
3873+
3874+
Notice that pandas uses index alignment in case of `value` from type `Series`:
3875+
3876+
>>> df.insert(0, "col0", pd.Series([5, 6], index=[1, 2]))
3877+
>>> df
3878+
col0 col1 col1 newcol col2
3879+
0 NaN 100 1 99 3
3880+
1 5.0 100 2 99 4
38733881
"""
38743882
if allow_duplicates and not self.flags.allows_duplicate_labels:
38753883
raise ValueError(

0 commit comments

Comments
 (0)