lastyear = row.dte - timedelta(days=365)
df2 = df[df.dte < lastyear].B.head(depth)
print(row.name, np.mean(df2))
df.apply(calculateC2, axis=1)
how to vectorise Pandas calculation that is based on last x rows of data