1. Learn
  2. /
  3. 课程
  4. /
  5. 使用 pandas 连接数据

Connected

道练习

某月的乘车总人数

您的目标是找出在 7 月(month == 7)工作日(day_type == 'Weekday')里,芝加哥公共交通系统中经过 Wilson 站(station_name == 'Wilson')的乘客一共乘坐了多少次。幸运的是,芝加哥提供了这类明细数据,但分散在 3 个不同的表中。您需要将这些表合并起来,才能回答这个问题。这个数据与您此前见到的业务数据不同,但回答问题所需的信息都已提供。

cal、ridership 和 stations 这 3 个 DataFrame 已为您加载。它们之间的关系见下图。

表关系图。cal 表通过 year、month 和 day 与 ridership 表关联;ridership 表通过 station_id 与 stations 表关联。

说明 1 / 共 3 个

undefined XP
    1
    2
    3
  • 将 ridership 与 cal 表合并,左侧以 ridership 开始,并将结果保存为变量 ridership_cal。如果代码运行时间过长,可能是合并条件不正确。