how to add a lag column in pandas code example Example: lag function in pandas df['Data_lagged'] = df.groupby(['Group'])['Data'].shift(1)