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.

More Python tasks

Back to the full Pandas cheat sheet