Is there a way to consecutively combine the values of columns in a pandas dataframe to reduce the amount of missing data? Preferably in a "hierarchical" order (like: "keep all values of column A, if something is missing then use the value from column B, if something is still missing use the value from column C and so on)
It seems like a pretty straightforward task, but I have not been able do it. I have looked into the workings of the pandas-functions: join, merge, combine and combine_first, and I assume specific setup for one of these functions or a combination of these would do the trick, but I have no idea, how to execute this, so any suggestions or help would be very much appreciated.
An example code of the desired transformation:
import pandas as pd
import numpy as np
df = pd.DataFrame({'A': [1,2,3,4,np.nan, np.nan, np.nan, np.nan],
'B': [np.nan,np.nan,0.3,4,5, 0.6, 0.7, np.nan],
'C': [0.01, 0.2, 0.3, 0.04, 0.5, 0.06, 7, 8]})
print('Input')
print(df)
xx = pd.DataFrame({'A': [1,2,3,4,5,0.6,0.7,8],
'B': [np.nan,np.nan,0.3,4,5, 0.6, 0.7, np.nan],
'C': [0.01, 0.2, 0.3, 0.04, 0.5, 0.06, 7, 8]})
print('\nDesired output:')
print(xx)