Given the following DataFrame:
import numpy as np
import pandas as pd
df = pd.DataFrame({"ColA": [1, 2, np.nan, 4, np.nan],
"ColB": [np.nan, 7, np.nan, 9, 10]})
ColA ColB
0 1.0 NaN
1 2.0 7.0
2 NaN NaN
3 4.0 9.0
4 NaN 10.0
I want to replace the values of ColA with those of ColB, but I never want a NaN value to replace a non-NaN value. My desired output is the following DataFrame:
ColA ColB
0 1.0 NaN
1 7.0 7.0
2 NaN NaN
3 9.0 9.0
4 10.0 10.0
My actual data is quite large, so while I know that I can iterate row-by-row I am looking for a more efficient approach.