Timedeltas and Shifts in Python
From the Pandas cheat sheet ยท Dates and Time ยท verified Aug 2026
Timedeltas and Shifts
Calculate durations and compare adjacent rows.
python
df["duration"] = df["ended_at"] - df["started_at"]๐ Sort before shift or diff calculations
๐ก Timedelta arithmetic preserves units
๐ shift aligns prior values by index
๐ฏ Name derived time units explicitly
timedeltashiftdiff
Continue with Pandas
Save the full cheat sheet or work through every related task.