I calculated 7day_rolling_avg because irregularities in covid data by this code:
covid_df['7day_rolling_avg'] = covid_df['New cases'].rolling(7).mean()
But, by plotting a graph on top of each other new graph can be seen misrepresented by 3-4 days.
Code:
covid_df[covid_df["Country"]=="India"]['New cases'].plot()
covid_df[covid_df["Country"]=="India"]['7day_rolling_avg'].plot()
plt.legend()
plt.show()
Can someone give me any idea how can I fix it?
CodePudding user response:
use center=True
in rolling
covid_df['7day_rolling_avg'] = covid_df['New cases'].rolling(7, center=True).mean()