Get startedGet started for free

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.

This exercise is part of the course

Analyzing Police Activity with pandas

View Course

Exercise instructions

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

Hands-on interactive exercise

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

# 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=____)
Edit and Run Code