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
Anleitung zur Übung
- Examine the shape of the
riDataFrame. - Merge the
riandweather_ratingDataFrames using a left join. - Examine the shape of
ri_weatherto confirm that it has two more columns but the same number of rows asri. - Replace the index of
ri_weatherwith thestop_datetimecolumn.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# 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=____)