import numpy as np
df['Last_index_notnull'] = df.index.to_series().where(df.B.notnull(), np.nan
    ).ffill()
Efficient way to select most recent index with finite value in column from Pandas DataFrame?