Skip to content

Commit 011906e

Browse files
committed
DOC: add example to insert (pandas-dev#39313)
1 parent 0b16fb3 commit 011906e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pandas/core/frame.py

+7
Original file line numberDiff line numberDiff line change
@@ -3870,6 +3870,13 @@ 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+
>>> df.insert(0, "col0", pd.Series([5, 6], index=[1, 2]))
3876+
>>> df
3877+
col0 col1 col1 newcol col2
3878+
0 NaN 100 1 99 3
3879+
1 5.0 100 2 99 4
38733880
"""
38743881
if allow_duplicates and not self.flags.allows_duplicate_labels:
38753882
raise ValueError(

0 commit comments

Comments
 (0)