Advertisement
Guest User

groupby diff

a guest
Jul 2nd, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.34 KB | None | 0 0
  1. def apply_diff_func(df):
  2.     df['difference'] = df['col'].diff()
  3.     return df
  4.  
  5. outputdf = df.groupby('storeid').apply(apply_diff_func)
  6.  
  7.  
  8. def apply_shift_func(df):
  9.     df['shifted'] = df['col'].shift(1)
  10.     df['difference'] = df['col'] - df['difference']
  11.     return df
  12.  
  13. outputdf = df.groupby('storeid').apply(apply_diff_func)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement