Store Excel file exported from Pandas in AWS Store Excel file exported from Pandas in AWS flask flask

Store Excel file exported from Pandas in AWS


To add to balderman's answer, the complete code for getting it to S3 would be

import ioimport pandas as pdimport boto3# ...# make data frame 'df'with io.BytesIO() as output:  with pd.ExcelWriter(output, engine='xlsxwriter') as writer:    df.to_excel(writer)  data = output.getvalue()s3 = boto3.resource('s3')s3.Bucket('my-bucket').put_object(Key='data.xlsx', Body=data)

See also the XlsxWriter documentation.


Taken from here: Write to StringIO object using Pandas Excelwriter?

You can dump the 'output' to S3

# Note, Python 2 example. For Python 3 use: output = io.BytesIO().output = StringIO.StringIO()# Use the StringIO object as the filehandle.writer = pd.ExcelWriter(output, engine='xlsxwriter')