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
Exercise instructions
- Use a string method to concatenate
stop_date
andstop_time
(separated by a space), and store the result incombined
. - Convert
combined
todatetime
format, and store the result in a new column namedstop_datetime
. - Examine the DataFrame
.dtypes
to confirm thatstop_datetime
is adatetime
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(____)