import pandas as pd
import numpy as np
data = np.array([['', 'Col1', 'Col2', 'Col3'],
['Row1', 1, 2, 3],
['Row2', np.nan, 5, 6],
['Row3', 7, 8, 9]
])
df = pd.DataFrame(data=data[1:, 1:],
index=data[1:,0],
columns=data[0,1:])
OutPut:
Col1 Col2 Col3
Row1 1 2 3
Row2 nan 5 6
Row3 7 8 9
I would like to loop through the dataframe and replace the NaN value in Row2['Col1'] (current row in loop) with the value in Row1['Col3'] (different column from the previous record in loop)