Skip to content

Commit

Permalink
DOC: DataFrame.update doctests (#56219)
Browse files Browse the repository at this point in the history
* Add doctest showing dtype changing

* Fix docstring results

* Tidy

* Remove docs for changing dtype
  • Loading branch information
smij720 authored Nov 29, 2023
1 parent 8dd497a commit c1c6db7
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -8826,26 +8826,27 @@ def update(
1 b e
2 c f
For Series, its name attribute must be set.
>>> df = pd.DataFrame({'A': ['a', 'b', 'c'],
... 'B': ['x', 'y', 'z']})
>>> new_column = pd.Series(['d', 'e'], name='B', index=[0, 2])
>>> df.update(new_column)
>>> new_df = pd.DataFrame({'B': ['d', 'f']}, index=[0, 2])
>>> df.update(new_df)
>>> df
A B
0 a d
1 b y
2 c e
2 c f
For Series, its name attribute must be set.
>>> df = pd.DataFrame({'A': ['a', 'b', 'c'],
... 'B': ['x', 'y', 'z']})
>>> new_df = pd.DataFrame({'B': ['d', 'e']}, index=[1, 2])
>>> df.update(new_df)
>>> new_column = pd.Series(['d', 'e', 'f'], name='B')
>>> df.update(new_column)
>>> df
A B
0 a x
1 b d
2 c e
0 a d
1 b e
2 c f
If `other` contains NaNs the corresponding values are not updated
in the original dataframe.
Expand Down

0 comments on commit c1c6db7

Please sign in to comment.