@@ -4534,21 +4534,44 @@ def combiner(x, y, needs_i8_conversion=False):
4534
4534
def update (self , other , join = 'left' , overwrite = True , filter_func = None ,
4535
4535
raise_conflict = False ):
4536
4536
"""
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.
4539
4540
4540
4541
Parameters
4541
4542
----------
4542
4543
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.
4543
4548
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
4547
4560
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.
4552
4575
4553
4576
Examples
4554
4577
--------
@@ -4563,6 +4586,9 @@ def update(self, other, join='left', overwrite=True, filter_func=None,
4563
4586
1 2 5
4564
4587
2 3 6
4565
4588
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
+
4566
4592
>>> df = pd.DataFrame({'A': ['a', 'b', 'c'],
4567
4593
... 'B': ['x', 'y', 'z']})
4568
4594
>>> 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,
4573
4599
1 b e
4574
4600
2 c f
4575
4601
4602
+ For Series, it's name attribute must be set.
4603
+
4576
4604
>>> df = pd.DataFrame({'A': ['a', 'b', 'c'],
4577
4605
... 'B': ['x', 'y', 'z']})
4578
4606
>>> 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,
4592
4620
1 b d
4593
4621
2 c e
4594
4622
4595
- If `` other` ` contains NaNs the corresponding values are not updated
4623
+ If `other` contains NaNs the corresponding values are not updated
4596
4624
in the original dataframe.
4597
4625
4598
4626
>>> df = pd.DataFrame({'A': [1, 2, 3],
0 commit comments