Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. def leak_fix_shift(df, cols, state_col):
  2. # Fixes leaky data by shifting information back a year so the previous
  3. # year's data can be used for prediction.
  4. df = df.copy()
  5. states = df[state_col].value_counts().keys()
  6. for col in cols:
  7. for state in states:
  8. df.loc[df[state_col]==state, col] = df.loc[df[state_col]==state, col].shift(periods=1)
  9. return df
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement