Selected topic
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.
| 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.
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())
Some key takeaways from this example: