Rolling Window Statistics
Desliza para mostrar el menú
Rolling window statistics are essential tools in time series analysis, allowing you to capture trends and patterns that occur over a specified period. By applying calculations such as the mean or standard deviation over a moving window of fixed size, you can smooth out short-term fluctuations and highlight longer-term trends or volatility. This approach is particularly useful for identifying periods of increased or decreased variability in your data, which can signal important changes or events. Unlike static features, rolling window statistics dynamically adjust as new data points arrive, making them highly valuable for forecasting and anomaly detection tasks.
1234567891011121314import pandas as pd # Create a simple time series data = { "timestamp": pd.date_range(start="2024-01-01", periods=10, freq="D"), "value": [10, 12, 11, 13, 15, 16, 18, 17, 19, 20] } df = pd.DataFrame(data) # Calculate rolling mean and rolling standard deviation with a window of 3 df["rolling_mean_3"] = df["value"].rolling(window=3).mean() df["rolling_std_3"] = df["value"].rolling(window=3).std() print(df[["timestamp", "value", "rolling_mean_3", "rolling_std_3"]])
¡Gracias por tus comentarios!
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla