從樞紐分析表擷取子集
樞紐分析表其實就是索引已排序的 DataFrame,因此你已經學過的技巧都能用來擷取子集。特別是,.loc[] 搭配切片(slicing)的組合常常很好用。
已載入 pandas 並命名為 pd。temp_by_country_city_vs_year 已可使用。
本練習屬於課程
使用 pandas 進行資料操作
練習說明
在 temp_by_country_city_vs_year 上使用 .loc[] 擷取子集。
- 從 Egypt 到 India。
- 從 Egypt, Cairo 到 India, Delhi。
- 從 Egypt, Cairo 到 India, Delhi,以及從 2005 年到 2010 年。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Subset for Egypt to India
____
# Subset for Egypt, Cairo to India, Delhi
____
# Subset for Egypt, Cairo to India, Delhi, and 2005 to 2010
____