You can use where to check your df for another df where the condition is True , the values โโfrom df returned when false the values โโfrom df1 . In addition, in the case where the NaN values โโare in df1 , then an additional call to fillna(df) will use the values โโfrom df to fill these NaN and return the desired df:
In [178]: df = pd.DataFrame(np.random.randn(5,3)) df.iloc[1,2] = np.NaN print(df) df1 = pd.DataFrame(np.random.randn(5,3)) df1.iloc[0,0] = np.NaN print(df1) 0 1 2 0 2.671118 1.412880 1.666041 1 -0.281660 1.187589 NaN 2 -0.067425 0.850808 1.461418 3 -0.447670 0.307405 1.038676 4 -0.130232 -0.171420 1.192321 0 1 2 0 NaN -0.244273 -1.963712 1 -0.043011 -1.588891 0.784695 2 1.094911 0.894044 -0.320710 3 -1.537153 0.558547 -0.317115 4 -1.713988 -0.736463 -1.030797 In [179]: df.where(df > df1, df1).fillna(df) Out[179]: 0 1 2 0 2.671118 1.412880 1.666041 1 -0.043011 1.187589 0.784695 2 1.094911 0.894044 1.461418 3 -0.447670 0.558547 1.038676 4 -0.130232 -0.171420 1.192321
source share