【发布时间】:2019-04-26 18:01:28
【问题描述】:
我需要从 S3 读取一个 csv 文件(使用 boto)来创建 pandas 数据框。问题是我部分知道文件名。 我可以使用 glob 和 pd_read csv 从我的系统中读取文件(我知道文件的部分名称)。
如何使用 Boto 来做到这一点?
文件名是“CELLBH_testing_phase1_automated_1234xvy345.csv”,我只知道 CELLBH 是已知关键字。其余字符串不断变化。
使用 boto 读取文件的代码,我知道确切的文件名:
access_key="xxxxxxxxxx"
secret_key="xxxxxxxxxx"
conn=boto.connect_s3(
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
host='xxxxxxxxx',
is_secure=False,
calling_format=boto.s3.connection.OrdinaryCallingFormat(),
)
bucket=conn.get_bucket('npousecase',validate=False)
Test_File='CELLBH.csv'
k=Key(bucket,Test_File)
content=k.get_contents_as_string()
Test=pd.read_csv(StringIO.StringIO(content),sep=";",header=0)
读取文件“CELLBH_testing_phase1_automated_1234xvy345.csv”的代码(如果它在我的系统上)
data_dir="C:\\users\\adbharga\\Desktop\\Input"
os.chdir(data_dir)
## Reading files from Input Directory
for f in glob.glob('CELLBH*.csv'):
Test = pd.read_csv(f,sep=";",header=0)
如何使用 Boto 完成上述操作?希望问题很清楚。谢谢
【问题讨论】:
标签: python-3.x pandas boto