标题:“01 - 下载数据集” 权重: 02
所有从2008年到现在的TLC行程记录的原始数据源可以在这里 找到。 同一数据集的AWS托管位置可以在这里 找到。
出租车行程记录包括捕获上车和下车日期/时间、上车和下车位置、行程距离、分项费用、费率类型、付款类型和司机报告的乘客数量的字段。原始数据按月分为1个文件,分为黄色、绿色或ForHire,从2008年到2020年,每个文件约600 MB。整个原始数据集非常庞大。对于我们的实验室,我们将使用这些文件中的13个,约一年的行程数据,并仅关注标志性的黄色出租车行程。我们选择了2019年2月到2020年2月的行程数据,以避免COVID-19的影响。下面的数据字典描述了黄色出租车行程数据的原始特征列名及其各自的描述。所选数据集涵盖13个月,包含约9000万次行程。
我们可以使用Amazon SageMaker Data Wrangler从以下数据源导入数据:Amazon Simple Storage Service (Amazon S3)、Amazon Athena、Amazon Redshift和Snowflake。我们导入的数据集最多可包含1000列。对于本实验室,我们将使用Amazon S3作为首选数据源。在我们将数据集导入到Data Wrangler之前,让我们先将数据集从公开托管的位置复制到我们自己账户中的本地S3存储桶。
要复制数据集,请在SageMaker Studio中复制并执行下面的Python代码。建议在笔记本环境中执行此代码。 我们还建议将我们的S3存储桶与SageMaker Data Wrangler位于同一区域。
要创建一个SageMaker Studio笔记本,从启动器页面,点击如下图所示的"笔记本Python 3"选项,在"笔记本和计算资源"下。
将下面共享的代码片段复制并粘贴到启动的笔记本的单元格中(如下图所示),然后点击顶部工具栏上的播放图标执行它。
import boto3
import json
# 设置
REGION = 'us-east-1'
account_id = boto3.client('sts').get_caller_identity().get('Account')
bucket_name = f'{account_id}-{REGION}-dw-ts-lab'
# 在我们的账户中创建一个S3存储桶来下载数据集
s3 = boto3.resource('s3')
if REGION == 'us-east-1':
s3.create_bucket(Bucket=bucket_name)
else:
s3.create_bucket(Bucket=bucket_name,
CreateBucketConfiguration={'LocationConstraint': REGION})
# 从公开托管的位置复制数据集到我们的S3存储桶
trips = [
{'Bucket': 'nyc-tlc', 'Key': 'trip data/yellow_tripdata_2019-02.parquet'},
{'Bucket': 'nyc-tlc', 'Key': 'trip data/yellow_tripdata_2019-03.parquet'},
{'Bucket': 'nyc-tlc', 'Key': 'trip data/yellow_tripdata_2019-04.parquet'},
{'Bucket': 'nyc-tlc', 'Key': 'trip data/yellow_tripdata_2019-05.parquet'},
{'Bucket': 'nyc-tlc', 'Key': 'trip data/yellow_tripdata_2019-06.parquet'},
{'Bucket': 'nyc-tlc', 'Key': 'trip data/yellow_tripdata_2019-07.parquet'},
{'Bucket': 'nyc-tlc', 'Key': 'trip data/yellow_tripdata_2019-08.parquet'},
{'Bucket': 'nyc-tlc', 'Key': 'trip data/yellow_tripdata_2019-09.parquet'},
{'Bucket': 'nyc-tlc', 'Key': 'trip data/yellow_tripdata_2019-10.parquet'},
{'Bucket': 'nyc-tlc', 'Key': 'trip data/yellow_tripdata_2019-11.parquet'},
{'Bucket': 'nyc-tlc', 'Key': 'trip data/yellow_tripdata_2019-12.parquet'},
{'Bucket': 'nyc-tlc', 'Key': 'trip data/yellow_tripdata_2020-01.parquet'},
{'Bucket': 'nyc-tlc', 'Key': 'trip data/yellow_tripdata_2020-02.parquet'}
]
for trip in trips:
s3.meta.client.copy(trip, bucket_name, trip['Key'])
现在,由于我们已将原始行程数据上传到所需的S3存储桶,我们就可以开始探索和转换它了!