Skip to content

Working with Dates and Times in Python

Run the hidden code cell below to import the data used in this course.


1 hidden cell

Date functions

  • date() function takes in a year, day, month to convert into date time
  • weekday() checks for the day of the week
  • timedelta() use to add dates
  • date_object.strftime( 'text %y')
  • date_object.isoformat() converts to iso format date
  • datetime.strptime('string',format we want)
  • datetime.fromtimestamp(ts) converts sec to date time
  • timezone(timedelta) use to translate my date time
  • date_object.astimezone(timezone to be in )
  • tz.gettz('continent/city')

Explore Datasets

Use the DataFrames imported in the first cell to explore the data and practice your skills!

  • Count how many hurricanes made landfall each year in Florida using florida_hurricane_dates.
  • Reload the dataset datasets/capital-onebike.csv so that it correctly parses date and time columns.
  • Calculate the average trip duration of bike rentals on weekends in rides. Compare it with the average trip duration of bike rentals on weekdays.