I have a (example-) dataframe with 4 columns:
data = {\'A\': [\'a\', \'b\', \'c\', \'d\', \'e\', \'f\'], \'B\': [42, 52, np.nan, np.nan, np.nan, np.nan],
You can also use ffill with iloc:
ffill
iloc
df['E'] = df.iloc[:, 1:].ffill(1).iloc[:, -1].astype(int) df = df.iloc[:, [0, -1]] print(df) A E 0 a 42 1 b 52 2 c 31 3 d 2 4 e 62 5 f 70