Discover Seasonal Patterns
Advanced · Write the code · from Time Series: Detect Trends and Anomalies in Business Data
From the lesson: Step 4: Find Seasonality Patterns
Seasonality means repeating patterns at fixed intervals. In our data, we built in a weekend boost. But in real data, you'd need to discover these patterns. Grouping by day of week and by month reveals when sales peak and dip.
Read this part of the lessonAnalyze seasonality in the sales data:
1. Add a day_of_week column using the index's dayofweek property.
2. Add a day_name column using the index's day_name() method.
3. Calculate mean sales by day of week, sorted by the day_of_week number.
4. Find the best and worst days (by mean sales).
5. Print "=== WEEKLY PATTERN ===" then each day with its mean: "{day_name}: ${mean:.2f}".
6. Print "Best day: {name} (${mean:.2f})" and "Worst day: {name} (${mean:.2f})".
More Time Series exercises
- Build the Time Series DataFrameAdvanced
- Compute Moving AveragesAdvanced
- Measure the TrendAdvanced
- Flag Anomalous DaysAdvanced
- The Complete Trend ReportAdvanced
All Python exercises · 50 practice problems · Practical Projects quiz