It is quite straight forward to save a csv in s3
on the fly but when I am trying to save the same dataframe as excel
format then I cannot open it when I download the updated excel. Following is the code for saving a csv but what changes would be required to make it save as excel properly.
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randn(50, 4), columns=list('ABCD'))
csv_buffer = StringIO()
df.to_csv(csv_buffer)
s3 = boto3.client('s3')
s3.put_object(Bucket='my-bucket', Body=csv_buffer.getvalue(), Key='test.csv'.format(file=filename))
Note that just replacing .csv
with .xlsx
will not work.