Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def leak_fix_shift(df, cols, state_col):
- # Fixes leaky data by shifting information back a year so the previous
- # year's data can be used for prediction.
- df = df.copy()
- states = df[state_col].value_counts().keys()
- for col in cols:
- for state in states:
- df.loc[df[state_col]==state, col] = df.loc[df[state_col]==state, col].shift(periods=1)
- return df
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement