resample_panel¶
resample_panel
¶
resample_panel(panel: DataFrame, freq: str = '15min', *, time_col: str = 'fetched_at', by: tuple[str, ...] = ('system_id', 'station_id')) -> DataFrame
Resample each station series onto a fixed time grid, carrying the last state forward.
Availability is a step function (a station's count holds until the next change), so a
panel polled at irregular instants must be aligned to a regular grid before clustering,
correlation or plotting. Doing this per station with groupby().resample().ffill()
is four brittle lines that routinely break nullable dtypes; this is the one-call,
dtype-safe version. It carries the last observed state forward (it does not invent
values), so it is alignment, not imputation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
panel
|
DataFrame
|
Panel/frame with the grouping columns in |
required |
freq
|
str
|
Target grid (a pandas offset alias). |
"15min"
|
time_col
|
str
|
Timestamp column. |
"fetched_at"
|
by
|
tuple of str
|
Grouping keys present in |
("system_id", "station_id")
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
A flat panel on the |
See Also
build_availability_panel : Read and resample a Parquet lake in one step.
insert_explicit_gaps : Mark collection outages instead of filling them.
extract_snapshot_asof : Take a single cross-section.
Examples:
>>> import pandas as pd
>>> panel = pd.DataFrame({
... "station_id": "a",
... "fetched_at": pd.to_datetime(["2026-01-01T00:00Z", "2026-01-01T00:30Z"]),
... "num_bikes_available": [5, 8],
... })
>>> out = resample_panel(panel, "15min")
>>> out["num_bikes_available"].tolist()
[5, 5, 8]