ComenzarEmpieza gratis

Merging the DataFrames

In this exercise, you'll merge the ri and weather_rating DataFrames into a new DataFrame, ri_weather.

The DataFrames will be joined using the stop_date column from ri and the DATE column from weather_rating. Thankfully the date formatting matches exactly, which is not always the case!

Once the merge is complete, you'll set stop_datetime as the index, which is the column you saved in the previous exercise.

Este ejercicio forma parte del curso

Analyzing Police Activity with pandas

Ver curso

Instrucciones del ejercicio

  • Examine the shape of the ri DataFrame.
  • Merge the ri and weather_rating DataFrames using a left join.
  • Examine the shape of ri_weather to confirm that it has two more columns but the same number of rows as ri.
  • Replace the index of ri_weather with the stop_datetime column.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# Examine the shape of 'ri'
print(____)

# Merge 'ri' and 'weather_rating' using a left join
ri_weather = pd.merge(left=____, right=____, left_on='stop_date', right_on='DATE', how='____')

# Examine the shape of 'ri_weather'
print(____)

# Set 'stop_datetime' as the index of 'ri_weather'
ri_weather.set_index('____', inplace=____)
Editar y ejecutar código