準備這些 DataFrame
在這個練習中,你要把交通攔查與天氣評分這兩個 DataFrame 整理好,以便後續合併:
- 對
riDataFrame,把作為索引的stop_datetime搬回成為一個欄位,因為在合併時索引會遺失。 - 對
weatherDataFrame,選取DATE與rating欄位,並放進新的 DataFrame。
本練習屬於課程
使用 pandas 分析警方執法活動
練習說明
- 重設
riDataFrame 的索引。 - 檢視
ri的前幾列,確認stop_datetime現在是 DataFrame 的一個欄位,且索引已變成預設的整數索引。 - 建立名為
weather_rating的新 DataFrame,只包含weatherDataFrame 中的DATE與rating欄位。 - 檢視
weather_rating的前幾列,確認其中包含正確的欄位。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# 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(____)