0
0
Pandasdata~5 mins

Date arithmetic with timedelta in Pandas - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is timedelta used for in pandas?

timedelta represents a duration or difference between two dates or times. It helps you add or subtract time from dates easily.

Click to reveal answer
beginner
How do you add 5 days to a pandas Timestamp?

You add pd.Timedelta(days=5) to the Timestamp. For example: new_date = old_date + pd.Timedelta(days=5).

Click to reveal answer
beginner
What happens if you subtract two pandas Timestamps?

Subtracting two Timestamps gives a Timedelta object representing the time difference between them.

Click to reveal answer
beginner
How can you create a Timedelta of 3 hours and 30 minutes?

Use pd.Timedelta(hours=3, minutes=30) to create a duration of 3 hours and 30 minutes.

Click to reveal answer
beginner
Why is timedelta useful in real life?

It helps calculate deadlines, durations, or intervals like how many days until a birthday or how long a project took.

Click to reveal answer
What does pd.Timedelta(days=7) represent?
AA time zone offset
BA duration of 7 days
CA timestamp at 7 AM
DA date 7 days ago
If date1 is January 10 and date2 is January 5, what is date1 - date2?
AJanuary 5
BJanuary 15
C5 days
DError
How do you subtract 2 hours from a pandas Timestamp?
Atimestamp.subtract(2)
Btimestamp + pd.Timedelta(hours=2)
Ctimestamp - 2
Dtimestamp - pd.Timedelta(hours=2)
Which of these is NOT a valid way to create a Timedelta?
Apd.Timedelta(1, 2)
Bpd.Timedelta('1 days 2 hours')
Cpd.Timedelta(days=1, hours=2)
Dpd.Timedelta(minutes=30)
What type of object results from adding a Timedelta to a Timestamp?
ATimestamp
BTimedelta
CDatetimeIndex
DString
Explain how you would calculate the number of days between two dates using pandas.
Think about subtracting dates and what type of object you get.
You got /3 concepts.
    Describe how to add 10 minutes to a pandas Timestamp and why this might be useful.
    Consider how durations help adjust times.
    You got /3 concepts.