1. mix
The mix
function does an element-wise comparison based on the given function.
As an example, we will select the utmost value out of two values for every position. It’ll be more clear after we do the instance.
combined_df = df1.mix(df2, np.maximum)
Take a take a look at the worth in the primary row and first column. The combined DataFrame has the larger one in all 5 and a couple of.
If one in all the values is NaN
(i.e. missing value), the combined DataFrame at this position has NaN
as well because Pandas can’t compare a worth with a missing value.
We are able to select a continuing value to be utilized in the case of missing values through the use of the fill_value
parameter. Missing values are crammed with this value before comparing them to the values in the opposite DataFrame.
combined_df = df1.mix(df2, np.maximum, fill_value=0)
There are two NaN
values in df1, that are crammed with 0 after which in comparison with the values in the identical position of df2
.