Skip to content

Instantly share code, notes, and snippets.

@clayh53
Created December 7, 2020 21:46
Show Gist options
  • Save clayh53/ae4771e1a59afa15f42357ea59ff52fc to your computer and use it in GitHub Desktop.
Save clayh53/ae4771e1a59afa15f42357ea59ff52fc to your computer and use it in GitHub Desktop.
# calculate an average death rate from lagged data
avg_death_from_positive_cases = df["death_prediction_scalar"].rolling(window=rolling_avg).mean()
stable_period = 45
start = lag - stable_period # calculates the index from end of dataframe to start the calculation
death_factor = avg_death_from_positive_cases[start:lag].mean() # average of smoothed data
# copy death scalar to an entire column
df['avg_death_factor'] = [death_factor] * len(df.index) # copies value to entire column
df['predicted_death'] = df['positiveIncrease'] * df['avg_death_factor']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment