Analyzing Time Series Data with Resampling and Window Functions
Instruction: Illustrate the use of resampling and window functions in Pandas for time series data analysis.
Context: This question explores the candidate's expertise in time series analysis, specifically using resampling and window functions for data summarization and transformation.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
Resampling creates time bins; rolling computes a moving window at each observation. Neither automatically fills missing observations or proves a trend.
import pandas as pd s = pd.Series([10., 20., 40.], index=pd.to_datetime([ "2026-01-01", "2026-01-03", "2026-02-01"])) monthly = s.resample("ME").sum(min_count=1) by_rows = s.rolling(2, min_periods=2).mean() by_time = s.rolling("7D", min_periods=1).mean() assert monthly.tolist() == [30., 40.] assert by_rows.iloc[-1] == 30...