[英]Convert pandas dataframe to parquet format and upload to s3 bucket
[英]Convert Pandas Dataframe to Image and Upload Directly to S3 Bucket Without Saving Locally Using Python
我正在編寫一個 Python 腳本,我將在 AWS Lamba function 中運行該腳本。 python 腳本將生成一個 pandas dataframe,我想將其轉換為 a.jpeg 或 .png。 我希望將此圖像文件直接寫入 S3 存儲桶,而無需將其保存到本地計算機上的文件夾中。 我已經對 boto3 進行了研究,並擁有 AWS 的訪問密鑰以從 S3 讀取和寫入,但我需要幫助將 pandas dataframe 轉換為圖像文件,然后直接上傳到 s3 存儲桶。
我在dataframe_image
存儲庫上創建了一個問題,向圖書館作者提出了這個問題,下面是我對他的建議的實現:
import boto3
import dataframe_image as dfi
from io import BytesIO
# create the buffer in which to store the generated image
png_io = BytesIO()
# assuming that your dataframe is stored as `df` variable
df.dfi.export(png_io)
# create the boto3 client and upload the BytesIO directly;
# create your client in whatever way works for you
session = boto3.session.Session(aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, region_name=region_name)
s3_client = session.client('s3')
s3_client.upload_fileobj(png_io, 'your_destination_folder/your_destination_file')
有關更多信息,請查看此TechOverflow 帖子和此StackOverflow 帖子。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.