1. 学习
  2. /
  3. 课程
  4. /
  5. 使用 pandas 进行数据处理

Connected

练习

设置与移除索引

pandas 允许您将某些列指定为索引(index)。这样在取子集时代码更简洁,在某些情况下查找也更高效。

在本章中,您将使用 temperatures,这是一个包含全球各城市平均气温的 DataFrame。pandas 已以 pd 导入。

说明

100 XP
  • 查看 temperatures。
  • 将 temperatures 的索引设为 "city",并保存为 temperatures_ind。
  • 查看 temperatures_ind。它与 temperatures 有何不同?
  • 重置 temperatures_ind 的索引,并保留其索引内容。
  • 重置 temperatures_ind 的索引,并丢弃其索引内容。