CommencerCommencer gratuitement

Seasonality and moving averages

Stepping back, we will now look at the overall revenue data for our meditation app. We saw strong purchase growth in one of our products, and now we want to see if that is leading to a corresponding rise in revenue. As you may expect, revenue is very seasonal, so we want to correct for that and unlock macro trends.

In this exercise, we will correct for weekly, monthly, and yearly seasonality and plot these over our raw data. This can reveal trends in a very powerful way.

The revenue data is loaded for you as daily_revenue.

Cet exercice fait partie du cours

Customer Analytics and A/B Testing in Python

Afficher le cours

Instructions

  • Using the .rolling() method, find the rolling average of the data with a 7 day window and store it in a column 7_day_rev.
  • Find the monthly (28 days) rolling average and store it in a column 28_day_rev.
  • Find the yearly (365 days) rolling average and store it in a column 365_day_rev.
  • Hit 'Submit Answer' to plot the three calculated rolling averages together along with the raw data.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Compute 7_day_rev
daily_revenue['7_day_rev'] = daily_revenue.revenue.____(window=____,center=False).____

# Compute 28_day_rev
daily_revenue['28_day_rev'] = daily_revenue.revenue.____(window=____,center=False).____
    
# Compute 365_day_rev
daily_revenue['365_day_rev'] = daily_revenue.revenue.____(window=____,center=False).____
    
# Plot date, and revenue, along with the 3 rolling functions (in order)    
daily_revenue.plot(x='date', y=['revenue', '7_day_rev', '28_day_rev', '365_day_rev', ])
plt.show()
Modifier et exécuter le code