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

Connected

练习

统计分类变量

计数可以帮助您快速了解数据概况,并发现平时不容易注意到的异常或有趣之处。本练习中,您将使用上一个练习中创建的 DataFrame,统计每种门店类型的数量,以及每个部门编号对应的门店数量:

# Drop duplicate store/type combinations
store_types = sales.drop_duplicates(subset=["store", "type"])

# Drop duplicate store/department combinations
store_depts = sales.drop_duplicates(subset=["store", "department"])

您在上一个练习中创建的 store_types 和 store_depts DataFrame 已可用,且已将 pandas 以 pd 导入。

说明

100 XP
  • 在 store_types 中统计各门店 type 的数量。
  • 在 store_types 中统计各门店 type 的占比。
  • 在 store_depts 中统计各 department 的门店数量,并按计数降序排序。
  • 在 store_depts 中统计各 department 的门店占比,并按占比降序排序。