</>
Skip to content
Data Science lessons (40/42)

Data Science — Time Series

Time series components

  1. Trend: Long-term direction
  2. Seasonality: Regular patterns
  3. Noise: Random variation

Basic analysis

import pandas as pd
import matplotlib.pyplot as plt

# Load time series
df = pd.read_csv('data.csv', parse_dates=['date'], index_col='date')

# Plot
df['value'].plot(figsize=(10, 6))
plt.show()

Rolling statistics

# Moving average
df['ma_7'] = df['value'].rolling(window=7).mean()
df['ma_30'] = df['value'].rolling(window=30).mean()

ARIMA

from statsmodels.tsa.arima.model import ARIMA

model = ARIMA(df['value'], order=(1, 1, 1))
fitted = model.fit()
forecast = fitted.forecast(steps=30)

Prophet

from prophet import Prophet

df_prophet = df.reset_index()
df_prophet.columns = ['ds', 'y']

model = Prophet()
model.fit(df_prophet)

future = model.make_future_dataframe(periods=30)
forecast = model.predict(future)

Mini Practice

  1. Analyze trends
  2. Detect seasonality
  3. Build ARIMA model
  4. Use Prophet

Up Next

Continue with NLP - Natural Language Processing.

Related Topics

Frequently Asked Questions about Time Series

What is Time Series in Data Science?

Time Series is a fundamental concept in Data Science. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Time Series?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Time Series.

Why is Time Series important in Data Science?

Time Series is essential for Data Science development. Understanding this concept will help you write better code and solve real-world problems more effectively.