Rolling operations on a groupby object automatically ignore NaNs in recent Pandas versions.
groupby
df.groupby('var1')['value'].rolling(3, min_periods=1).mean().reset_index(level=0, drop=True).sort_index()