開始使用免費開始

準備這些 DataFrame

在這個練習中,你要把交通攔查與天氣評分這兩個 DataFrame 整理好,以便後續合併:

  1. ri DataFrame,把作為索引的 stop_datetime 搬回成為一個欄位,因為在合併時索引會遺失。
  2. weather DataFrame,選取 DATErating 欄位,並放進新的 DataFrame。

本練習屬於課程

使用 pandas 分析警方執法活動

檢視課程

練習說明

  • 重設 ri DataFrame 的索引。
  • 檢視 ri 的前幾列,確認 stop_datetime 現在是 DataFrame 的一個欄位,且索引已變成預設的整數索引。
  • 建立名為 weather_rating 的新 DataFrame,只包含 weather DataFrame 中的 DATErating 欄位。
  • 檢視 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(____)
編輯並執行程式碼