ComeçarComece de graça

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.

Este exercício faz parte do curso

Analyzing Police Activity with pandas

Ver curso

Instruções do exercício

  • 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.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# 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(____)
Editar e executar o código