Pandas DataFrame update() Method
Example
Update the DataFrame with the data from another DataFrame, Emil is 17 not 16:
import pandas as pd
df1 = pd.DataFrame([["Emil", "Tobias",
"Linus"], [16, 14, 10]])
df2 = pd.DataFrame([["Emil"], [17]])
df1.update(df2)
Try it Yourself »
Definition and Usage
The update()
method updates a DataFrame with
elements from another similar object (like another DataFrame).
Note: this method does NOT return a new DataFrame.
The updating is done to the original DataFrame.
Syntax
dataframe.update(other, join, overwrite, filter_func,
errors)
Parameters
The join
, overwrite
,
filter_func
, errors
parameters are
keyword arguments.
Parameter | Value | Description |
---|---|---|
other | Required. A DataFrame. | |
join | 'left' |
Optional. Default 'left'. Specifies which of the two objects to update. Note: only 'left' is allowed (for now) |
overwrite | True |
Optional. Default True. Specifies whether to overwrite NULL values or not |
filter_func | Function | Optional. Specifies a function to execute for each replaced element. The function should return True for elements that should be updated |
errors | 'raise' |
Optional. Default 'ignore'. If 'raise': an error will be raised both DataFrames has a NULL value for the same element |
Return Value
This method returns None. The updating is done to the original DataFrame.
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.