開始使用免費開始

依索引值排序

先前你是透過呼叫 .sort_values() 來調整 DataFrame 的列順序。能夠依索引中的元素排序也很有用。為此,你需要使用 .sort_index()

pandas 已載入為 pdtemperatures_ind 具有 countrycity 的多層索引,且已可使用。

本練習屬於課程

使用 pandas 進行資料操作

檢視課程

練習說明

  • 依索引值排序 temperatures_ind
  • "city" 層級的索引值排序 temperatures_ind
  • 先依國家遞增、再依城市遞減排序 temperatures_ind

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Sort temperatures_ind by index values
print(____)

# Sort temperatures_ind by index values at the city level
print(____)

# Sort temperatures_ind by country then descending city
print(____)
編輯並執行程式碼