我需要在 python 中使用 boto3 从 S3 存储桶中读取多个 csv 文件,最后将这些文件合并到 pandas 中的单个数据框中。
我能够从 python 中的以下脚本读取单个文件
s3 = boto3.resource('s3')
bucket = s3.Bucket('test-bucket')
for obj in bucket.objects.all():
key = obj.key
body = obj.get()['Body'].read()
以下是我的路径
files/splittedfiles/Code-345678
在 Code-345678
我有多个 csv
我必须读取并将其组合到熊猫中的单个数据帧的文件
另外,我如何将选定的列表 Codes
作为列表传递,以便它只读取这些文件夹。例如
files/splittedfiles/Code-345678
files/splittedfiles/Code-345679
files/splittedfiles/Code-345680
files/splittedfiles/Code-345681
files/splittedfiles/Code-345682
从上面我只需要阅读以下代码下的文件。
345678,345679,345682
我怎样才能在 python 中做到这一点?
原文由 Neil 发布,翻译遵循 CC BY-SA 4.0 许可协议
修改答案 1 以克服错误
DataFrame constructor not properly called!
代码: