mask = pd.isnull(df['E'][1:])
df['E'][1:][mask] = fun(df['B'][1:].values, df['B'][1:].values, df['B'][:-1
    ].values, df['B'][:-1].values)
return df
Apply function between subsequent rows in more efficient way with Pandas