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.
Diese Übung ist Teil des Kurses
Analyzing Police Activity with pandas
Anleitung zur Übung
- Use a string method to concatenate
stop_dateandstop_time(separated by a space), and store the result incombined. - Convert
combinedtodatetimeformat, and store the result in a new column namedstop_datetime. - Examine the DataFrame
.dtypesto confirm thatstop_datetimeis adatetimecolumn.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# 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(____)