Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to avoid misrepresented data by 3 days in the rolling mean graph in python?

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

covid_df[covid_df["Country"]=="India"]['New cases'].plot()
covid_df[covid_df["Country"]=="India"]['7day_rolling_avg'].plot()
plt.legend()
plt.show()

Output:
enter image description here

Can someone give me any idea how can I fix it?

>Solution :

use center=True in rolling

covid_df['7day_rolling_avg'] = covid_df['New cases'].rolling(7, center=True).mean()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading