Selected topic
Rolling Statistics
Prefer practical output? Use related tools below while reading.
Rolling statistics is a technique used in exploratory data analysis (EDA) to calculate statistical metrics on a subset of data, typically based on a moving window or a rolling average. This allows you to analyze patterns and trends in your data over time.
Here are the key concepts:
### Types of Rolling Statistics
python
import pandas as pd
import numpy as np# Create a sample DataFrame with 10 data points
df = pd.DataFrame({
'Date': pd.date_range(start='2022-01-01', periods=10),
'Value': np.random.randint(1, 100, size=10)
})
print(df)
# Calculate rolling statistics (moving average and standard deviation) over a window of 3 data points
rolling_stats = df['Value'].rolling(window=3).agg(['mean', 'std'])
print(rolling_stats)
In this example, the rolling function applies a moving average and standard deviation to each window of 3 data points.