Rolling windows and time zones
3.1.1
Calculate moving summaries and group timestamps using the intended local date.
On this page
Choose a count-based or time-based window
rolling(3) uses a window of up to three observations at each position. rolling("7D") uses time with a suitable datetime-like index. Specify min_periods to make the minimum usable observations explicit, and sort time data first.
import pandas as pd
sales = pd.Series([2, 4, 6, 8])
print(sales.rolling(3, min_periods=1).mean().tolist())
Example output
[2.0, 3.0, 4.0, 6.0]
Localize or convert timestamps
tz_localize assigns a time zone to naive timestamps. tz_convert changes the displayed time zone of aware timestamps while preserving the instant. Convert before using a local day or month when the report is defined in local time.
import pandas as pd
instant = pd.Timestamp("2023-02-28 21:00", tz="UTC")
print(instant.tz_convert("Asia/Yangon").isoformat())
Example output
2023-03-01T03:30:00+06:30