Preparing the DataFrames
In this exercise, you'll prepare the traffic stop and weather rating DataFrames so that they're ready to be merged:
- With the
ri
DataFrame, you'll move thestop_datetime
index to a column since the index will be lost during the merge. - With the
weather
DataFrame, you'll select theDATE
andrating
columns and put them in a new DataFrame.
This exercise is part of the course
Analyzing Police Activity with pandas
Exercise instructions
- Reset the index of the
ri
DataFrame. - Examine the head of
ri
to verify thatstop_datetime
is now a DataFrame column, and the index is now the default integer index. - Create a new DataFrame named
weather_rating
that contains only theDATE
andrating
columns from theweather
DataFrame. - Examine the head of
weather_rating
to verify that it contains the proper columns.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Reset the index of 'ri'
# Examine the head of 'ri'
print(____)
# Create a DataFrame from the 'DATE' and 'rating' columns
# Examine the head of 'weather_rating'
print(____)