我在AWS S3存储桶中有一个csv文件。如何下载CSV并将其分配给numpy数组?
[使用python 3.6 / boto3]
我尝试了多种形式,包括:
s3 = boto3.resource('s3', region_name=region)
obj = s3.Object(bucket, key)
with io.BytesIO(obj.get()["Body"].read()) as f:
# rewind the file
f.seek(0)
arr_data = numpy.load(f)
arr_data = numpy.genfromtxt('https://BUCKETNAME.s3-eu-west-1.amazonaws.com/folder/infile.csv',dtype='str',delimiter=',')
这也不起作用
基本上,我正在尝试在S3中复制: arr_data = np.genfromtxt('path ... input.csv',dtype ='str',delimiter =',')
答案 0 :(得分:0)
我能够使用它们之间的熊猫将csv转换为numpy数组...不确定这是否是您要的内容。但是,这是我的操作方式:
import pandas as pd
import numpy as np
data_location = 's3://<path>'
data = pd.read_csv(data_location)
data_numpy = data.value.values.reshape(-1,1)