简体   繁体   English

从 AWS S3 中可用的 gzip 文件中读取内容

[英]Reading contents from gzip file which was available in AWS S3

Reading contents from gzip file in python dataframe which is available in AWS S3.从 python dataframe 中的 gzip 文件中读取内容,该文件在 AWS S3 中可用。

Want to convert dataframe.想转换dataframe。

In case if you are trying to get json data to dataframe Here is the code.如果您尝试将 json 数据转换为 dataframe 这是代码。

import pandas as pd
import boto3
from io import StringIO
import gzip
resource = boto3.resource('s3',aws_access_key_id = '',
    aws_secret_access_key = '')
    list_keys= []
    lst = []
    for key in client.list_objects(Bucket='bucket_name',Prefix = 'Folder name')['Contents']:
        list_keys.append(key["Key"])
    for key in list_keys:
        try:
            obj = resource.Object("bucket_name", key)
            with gzip.GzipFile(fileobj=obj.get()["Body"]) as gzipfile:
                temp_data = pd.read_json(StringIO(gzipfile.read().decode('UTF-8')),lines=True)
                lst.append(temp_data)
        except Exception as e:
            pass
    df = pd.concat(lst,ignore_index = True)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 R 中的 AWS S3 读取 gzip 文件的内容 - Reading contents of a gzip file from a AWS S3 in R 从 Python 中的 AWS S3 读取 gzip 文件的内容 - Reading contents of a gzip file from a AWS S3 in Python 如何从 AWS CloudFront 和 S3 请求 gzip javascript 文件 - How do I Request a gzip javascript file from AWS CloudFront and S3 python pandas 从 s3 读取 json gzip 文件 - python pandas read json gzip file from s3 从 AWS lambda function 中的 s3 存储桶中读取 .mdb 或 .accdb 文件并使用 python 将其转换为 excel 或 csv - Reading .mdb or .accdb file from s3 bucket in AWS lambda function and converting it into excel or csv using python 从 lambda function 读取 AWS S3 内的 excel 文件时超时 - timeout when reading excel file inside AWS S3 from lambda function 使用 org.apache.hadoop:hadoop-aws 从 pyspark 中的 s3 读取文件 - Reading file from s3 in pyspark using org.apache.hadoop:hadoop-aws 根据将文件从一个 S3 存储桶复制到另一个存储桶的清单文件触发 AWS Lambda function - Trigger AWS Lambda function based on a manifest file which copies files from one S3 bucket to another Python:Stream 来自 s3 的 gzip 文件 - Python: Stream gzip files from s3 从私有 S3 存储桶读取文件到 pandas dataframe - Reading a file from a private S3 bucket to a pandas dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM