Skip to content

Commit 21ae073

Browse files
kantologistjorisvandenbossche
authored andcommitted
DOC: update the DataFrame.update() docstring (#20201)
1 parent fc42e6e commit 21ae073

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

pandas/core/frame.py

+38-10
Original file line numberDiff line numberDiff line change
@@ -4534,21 +4534,44 @@ def combiner(x, y, needs_i8_conversion=False):
45344534
def update(self, other, join='left', overwrite=True, filter_func=None,
45354535
raise_conflict=False):
45364536
"""
4537-
Modify DataFrame in place using non-NA values from passed
4538-
DataFrame. Aligns on indices
4537+
Modify in place using non-NA values from another DataFrame.
4538+
4539+
Aligns on indices. There is no return value.
45394540
45404541
Parameters
45414542
----------
45424543
other : DataFrame, or object coercible into a DataFrame
4544+
Should have at least one matching index/column label
4545+
with the original DataFrame. If a Series is passed,
4546+
its name attribute must be set, and that will be
4547+
used as the column name to align with the original DataFrame.
45434548
join : {'left'}, default 'left'
4544-
overwrite : boolean, default True
4545-
If True then overwrite values for common keys in the calling frame
4546-
filter_func : callable(1d-array) -> 1d-array<boolean>, default None
4549+
Only left join is implemented, keeping the index and columns of the
4550+
original object.
4551+
overwrite : bool, default True
4552+
How to handle non-NA values for overlapping keys:
4553+
4554+
* True: overwrite original DataFrame's values
4555+
with values from `other`.
4556+
* False: only update values that are NA in
4557+
the original DataFrame.
4558+
4559+
filter_func : callable(1d-array) -> boolean 1d-array, optional
45474560
Can choose to replace values other than NA. Return True for values
4548-
that should be updated
4549-
raise_conflict : boolean
4550-
If True, will raise an error if the DataFrame and other both
4551-
contain data in the same place.
4561+
that should be updated.
4562+
raise_conflict : bool, default False
4563+
If True, will raise a ValueError if the DataFrame and `other`
4564+
both contain non-NA data in the same place.
4565+
4566+
Raises
4567+
------
4568+
ValueError
4569+
When `raise_conflict` is True and there's overlapping non-NA data.
4570+
4571+
See Also
4572+
--------
4573+
dict.update : Similar method for dictionaries.
4574+
DataFrame.merge : For column(s)-on-columns(s) operations.
45524575
45534576
Examples
45544577
--------
@@ -4563,6 +4586,9 @@ def update(self, other, join='left', overwrite=True, filter_func=None,
45634586
1 2 5
45644587
2 3 6
45654588
4589+
The DataFrame's length does not increase as a result of the update,
4590+
only values at matching index/column labels are updated.
4591+
45664592
>>> df = pd.DataFrame({'A': ['a', 'b', 'c'],
45674593
... 'B': ['x', 'y', 'z']})
45684594
>>> new_df = pd.DataFrame({'B': ['d', 'e', 'f', 'g', 'h', 'i']})
@@ -4573,6 +4599,8 @@ def update(self, other, join='left', overwrite=True, filter_func=None,
45734599
1 b e
45744600
2 c f
45754601
4602+
For Series, it's name attribute must be set.
4603+
45764604
>>> df = pd.DataFrame({'A': ['a', 'b', 'c'],
45774605
... 'B': ['x', 'y', 'z']})
45784606
>>> new_column = pd.Series(['d', 'e'], name='B', index=[0, 2])
@@ -4592,7 +4620,7 @@ def update(self, other, join='left', overwrite=True, filter_func=None,
45924620
1 b d
45934621
2 c e
45944622
4595-
If ``other`` contains NaNs the corresponding values are not updated
4623+
If `other` contains NaNs the corresponding values are not updated
45964624
in the original dataframe.
45974625
45984626
>>> df = pd.DataFrame({'A': [1, 2, 3],

0 commit comments

Comments
 (0)