Selected topic

Trend Analysis

Trend Analysis

Prefer practical output? Use related tools below while reading.

Trend analysis is a statistical technique used to identify patterns or trends in data over time. In the context of Exploratory Data Analysis (EDA), trend analysis helps to understand how variables change or evolve over time, which can inform business decisions and predictions.

Example:


Suppose we have a dataset containing daily sales of an e-commerce company for the past year:

| Date | Sales |
|------------|-------|
| 2022-01-01 | 100 |
| 2022-01-02 | 120 |
| 2022-01-03 | 110 |
| ... | ... |
| 2022-12-31 | 2000 |

To perform trend analysis, we can use a simple moving average (SMA) or exponential smoothing (ES) technique.

Code:


python
import pandas as pd

# Load data
df = pd.read_csv('sales_data.csv')

# Create date column as datetime type
df['Date'] = pd.to_datetime(df['Date'])

# Sort by date
df.sort_values(by='Date', inplace=True)

# Calculate moving average (SMA)
df['Moving_Avg'] = df['Sales'].rolling(window=30).mean()

# Print the first 5 rows of the dataframe
print(df.head())


Output:


| Date | Sales | Moving_Avg |
|------------|-------|------------|
| 2022-01-01 | 100 | NaN |
| 2022-01-02 | 120 | NaN |
| 2022-01-03 | 110 | NaN |
| ... | ... | ... |
| 2022-12-31 | 2000 | 154.24 |

Interpretation:


The trend analysis reveals that the sales have been increasing over time, with a slight dip in June and July. The moving average (SMA) indicates that the sales are generally trending upwards.

Some key takeaways from this example:

  1. Identifying trends: By analyzing the moving average, we can see that the sales have been increasing over time.
  2. Understanding seasonal fluctuations: We observed a dip in sales during June and July, which might be due to seasonal factors like holidays or summer vacations.
  3. Informing business decisions: The trend analysis provides valuable insights for business planning, such as forecasting future sales and adjusting marketing strategies accordingly.
Trend analysis is a fundamental concept in EDA that helps us make informed decisions based on data-driven insights.