Decompose Time-Series Data into Trend, Seasonal, and Residual Components
Beginner Mode

Start your terminal to use beginner mode.

Sign in to watch the walkthrough video

Sign In

Scenario

A CSV file contains daily temperature readings over multiple years. You need to decompose this time-series data to analyze its underlying patterns.

Task

Write a Python script at /home/interview/decompose_timeseries.py using statsmodels that reads /home/interview/temperature_data.csv, decomposes the temperature time-series into trend, seasonal, and residual components using additive decomposition, and saves each component to separate CSV files: /home/interview/trend.csv, /home/interview/seasonal.csv, and /home/interview/residual.csv.

Note: The statsmodels module is already installed.

Example

Input (temperature_data.csv):

date,temperature
2023-01-01,8.5
2023-01-02,9.2
...

Expected outputs:

  • trend.csv - Long-term trend component
  • seasonal.csv - Repeating seasonal pattern
  • residual.csv - Random fluctuations

Terminal requires a larger screen

Open this page on a desktop or tablet (≥ 768px) to launch the terminal and practice hands-on.

Linux Terminal Environment

Write and execute your solution in the terminal below.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →