Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Challenge: Negative Trip Duration | Working with Dates and Times in pandas
Dealing with Dates and Times in Python
course content

Course Content

Dealing with Dates and Times in Python

Dealing with Dates and Times in Python

1. Working with Dates
2. Working with Times
3. Timezones and Daylight Savings Time (DST)
4. Working with Dates and Times in pandas

Challenge: Negative Trip Duration

Well, in the last chapter you might notice that for the first 10 rows all the trips started before 13 hours (1 p.m.), and ended close to 00 hours. What if it's just AM/PM missing? Let's try to check it.

How can it be checked? Well, in our dataframe we also have trip_duration column representing the trip duration in seconds. What if we just add this duration to pickup_datetime and compare it with dropoff_datetime?

Please note, that you will need to use timedelta objects in this task since you want to 'shift' your datetime object for a certain time. To convert column to timedelta type use pd.to_timedelta() function with two arguments: column you want to convert, and unit - dimension used ('S' for seconds, 'm' for minutes, and so on).

Task

  1. Convert trip_duration column into timedelta type. Do not forget that trip_duration measures in seconds.
  2. Create new column dropoff_calculated as the result of adding pickup_datetime and trip_duration.
  3. Print first 10 rows for updated dataframe.

Please, do not change column names in square brackets.

Task

  1. Convert trip_duration column into timedelta type. Do not forget that trip_duration measures in seconds.
  2. Create new column dropoff_calculated as the result of adding pickup_datetime and trip_duration.
  3. Print first 10 rows for updated dataframe.

Please, do not change column names in square brackets.

Switch to desktop for real-world practiceContinue from where you are using one of the options below

Everything was clear?

Section 4. Chapter 5
toggle bottom row

Challenge: Negative Trip Duration

Well, in the last chapter you might notice that for the first 10 rows all the trips started before 13 hours (1 p.m.), and ended close to 00 hours. What if it's just AM/PM missing? Let's try to check it.

How can it be checked? Well, in our dataframe we also have trip_duration column representing the trip duration in seconds. What if we just add this duration to pickup_datetime and compare it with dropoff_datetime?

Please note, that you will need to use timedelta objects in this task since you want to 'shift' your datetime object for a certain time. To convert column to timedelta type use pd.to_timedelta() function with two arguments: column you want to convert, and unit - dimension used ('S' for seconds, 'm' for minutes, and so on).

Task

  1. Convert trip_duration column into timedelta type. Do not forget that trip_duration measures in seconds.
  2. Create new column dropoff_calculated as the result of adding pickup_datetime and trip_duration.
  3. Print first 10 rows for updated dataframe.

Please, do not change column names in square brackets.

Task

  1. Convert trip_duration column into timedelta type. Do not forget that trip_duration measures in seconds.
  2. Create new column dropoff_calculated as the result of adding pickup_datetime and trip_duration.
  3. Print first 10 rows for updated dataframe.

Please, do not change column names in square brackets.

Switch to desktop for real-world practiceContinue from where you are using one of the options below

Everything was clear?

Section 4. Chapter 5
toggle bottom row

Challenge: Negative Trip Duration

Well, in the last chapter you might notice that for the first 10 rows all the trips started before 13 hours (1 p.m.), and ended close to 00 hours. What if it's just AM/PM missing? Let's try to check it.

How can it be checked? Well, in our dataframe we also have trip_duration column representing the trip duration in seconds. What if we just add this duration to pickup_datetime and compare it with dropoff_datetime?

Please note, that you will need to use timedelta objects in this task since you want to 'shift' your datetime object for a certain time. To convert column to timedelta type use pd.to_timedelta() function with two arguments: column you want to convert, and unit - dimension used ('S' for seconds, 'm' for minutes, and so on).

Task

  1. Convert trip_duration column into timedelta type. Do not forget that trip_duration measures in seconds.
  2. Create new column dropoff_calculated as the result of adding pickup_datetime and trip_duration.
  3. Print first 10 rows for updated dataframe.

Please, do not change column names in square brackets.

Task

  1. Convert trip_duration column into timedelta type. Do not forget that trip_duration measures in seconds.
  2. Create new column dropoff_calculated as the result of adding pickup_datetime and trip_duration.
  3. Print first 10 rows for updated dataframe.

Please, do not change column names in square brackets.

Switch to desktop for real-world practiceContinue from where you are using one of the options below

Everything was clear?

Well, in the last chapter you might notice that for the first 10 rows all the trips started before 13 hours (1 p.m.), and ended close to 00 hours. What if it's just AM/PM missing? Let's try to check it.

How can it be checked? Well, in our dataframe we also have trip_duration column representing the trip duration in seconds. What if we just add this duration to pickup_datetime and compare it with dropoff_datetime?

Please note, that you will need to use timedelta objects in this task since you want to 'shift' your datetime object for a certain time. To convert column to timedelta type use pd.to_timedelta() function with two arguments: column you want to convert, and unit - dimension used ('S' for seconds, 'm' for minutes, and so on).

Task

  1. Convert trip_duration column into timedelta type. Do not forget that trip_duration measures in seconds.
  2. Create new column dropoff_calculated as the result of adding pickup_datetime and trip_duration.
  3. Print first 10 rows for updated dataframe.

Please, do not change column names in square brackets.

Switch to desktop for real-world practiceContinue from where you are using one of the options below
Section 4. Chapter 5
Switch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt