开始使用免费开始使用

合并 2 月的每日请求

距离 Sam 上次运行报告脚本已经过去一个月了,现在是时候为 2 月制作一份新报告。

她想上传 2 月的新报告并更新文件清单,基于上一个视频课程中完成的工作继续扩展:

Directory listing screenshot

她已经创建了 boto3 的 S3 客户端并存放在变量 s3 中。她把对象的内容存入了 request_files

您将帮助 Sam 通过从 gid-requests 存储桶下载文件并将其连接为一个 DataFrame,来汇总 2 月的请求!

本练习是课程的一部分

Python 中的 AWS Boto 入门

查看课程

练习说明

  • s3 加载每个对象。
  • 将其读入 pandas 并追加到 df_list
  • 连接 df_list 中的所有 DataFrame。
  • 预览该 DataFrame。

交互式实操练习

通过完成这段示例代码来试试这个练习。

df_list = [] 

# Load each object from s3
for file in request_files:
    s3_day_reqs = s3.____(Bucket='gid-requests', 
                                Key=file['Key'])
    # Read the DataFrame into pandas, append it to the list
    day_reqs = pd.read_csv(s3_day_reqs['____'])
    df_list.append(day_reqs)

# Concatenate all the DataFrames in the list
all_reqs = pd.____(df_list)

# Preview the DataFrame
all_reqs.head()
编辑并运行代码