Skip to content

Commit c1c6db7

Browse files
authored
DOC: DataFrame.update doctests (#56219)
* Add doctest showing dtype changing * Fix docstring results * Tidy * Remove docs for changing dtype
1 parent 8dd497a commit c1c6db7

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

pandas/core/frame.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8826,26 +8826,27 @@ def update(
88268826
1 b e
88278827
2 c f
88288828
8829-
For Series, its name attribute must be set.
8830-
88318829
>>> df = pd.DataFrame({'A': ['a', 'b', 'c'],
88328830
... 'B': ['x', 'y', 'z']})
8833-
>>> new_column = pd.Series(['d', 'e'], name='B', index=[0, 2])
8834-
>>> df.update(new_column)
8831+
>>> new_df = pd.DataFrame({'B': ['d', 'f']}, index=[0, 2])
8832+
>>> df.update(new_df)
88358833
>>> df
88368834
A B
88378835
0 a d
88388836
1 b y
8839-
2 c e
8837+
2 c f
8838+
8839+
For Series, its name attribute must be set.
8840+
88408841
>>> df = pd.DataFrame({'A': ['a', 'b', 'c'],
88418842
... 'B': ['x', 'y', 'z']})
8842-
>>> new_df = pd.DataFrame({'B': ['d', 'e']}, index=[1, 2])
8843-
>>> df.update(new_df)
8843+
>>> new_column = pd.Series(['d', 'e', 'f'], name='B')
8844+
>>> df.update(new_column)
88448845
>>> df
88458846
A B
8846-
0 a x
8847-
1 b d
8848-
2 c e
8847+
0 a d
8848+
1 b e
8849+
2 c f
88498850
88508851
If `other` contains NaNs the corresponding values are not updated
88518852
in the original dataframe.

0 commit comments

Comments
 (0)