Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.

Examples

In [1]:
import numpy as np
import pandas as pd
In [2]:
df1 = pd.DataFrame({'X': [None, 0], 'Y': [None, 5]})
df2 = pd.DataFrame({'X': [3, 3], 'Y': [4, 4]})
df1.combine_first(df2)
Out[2]:
X Y
0 3.0 4.0
1 0.0 5.0

Null values still persist if the location of that null value does not exist in other

In [3]:
df1 = pd.DataFrame({'X': [None, 0], 'Y': [5, None]})
df2 = pd.DataFrame({'Y': [4, 4], 'C': [2, 2]}, index=[1, 2])
df1.combine_first(df2)
Out[3]:
C X Y
0 NaN NaN 5.0
1 2.0 0.0 4.0
2 2.0 NaN 4.0