1. Learn
  2. /
  3. Courses
  4. /
  5. 使用 pandas 进行数据处理

Connected

Exercise

按索引值排序

之前,您通过调用 .sort_values() 更改了 DataFrame 的行顺序。按索引中的元素排序同样很有用。要实现这一点,您需要使用 .sort_index()。

pandas 已以 pd 导入。temperatures_ind 具有 country 和 city 的多级索引,且已提供。

Instructions

100 XP
  • 按索引值对 temperatures_ind 进行排序。
  • 按 "city" 层级的索引值对 temperatures_ind 进行排序。
  • 先按国家升序、再按城市降序对 temperatures_ind 进行排序。