Get startedGet started for free

Combining object columns

Currently, the date and time of each traffic stop are stored in separate object columns: stop_date and stop_time.

In this exercise, you'll combine these two columns into a single column, and then convert it to datetime format. This will enable convenient date-based attributes that we'll use later in the course.

This exercise is part of the course

Analyzing Police Activity with pandas

View Course

Exercise instructions

  • Use a string method to concatenate stop_date and stop_time (separated by a space), and store the result in combined.
  • Convert combined to datetime format, and store the result in a new column named stop_datetime.
  • Examine the DataFrame .dtypes to confirm that stop_datetime is a datetime column.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Concatenate 'stop_date' and 'stop_time' (separated by a space)
combined = ri.stop_date.____

# Convert 'combined' to datetime format
ri['stop_datetime'] = ____

# Examine the data types of the DataFrame
print(____)
Edit and Run Code