LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Analyzing Police Activity with pandas

Kurs anzeigen

Anleitung zur Übung

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

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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=____)
Code bearbeiten und ausführen