處理不同的欄位名稱
你可能想看看每種球季類型(pre、regular、post)的平均氣溫。天氣團隊帶來好消息也帶來「有點」壞消息……他們找到了 2016 與 2017 球季的資料。不過,看起來自從你上次拿到檔案後,他們更改了命名慣例。你需要先調整程式碼,才能產生氣溫結果。
games_places 資料框已載入,另外還有新的天氣資料框 weather_new。
本練習屬於課程
給試算表使用者的 pandas 合併實務
練習說明
- 檢視
games_places的前 5 列,以及weather_new的前 5 列。 - 將兩者進行合併,只保留同時存在於兩個資料集中的比賽。
- 檢視依球季類型分組的平均氣溫。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# View the first 5 rows of each data frame
print(____)
print(____)
# Join data frames
games_weather = games_places.____(____, left_on=____,
right_on=____, how=____)
# View average temperatures
print(games_weather.pivot_table(values='Temperature', index='SeasonType'))