I want to loop through my data and save every component based data in separate sheet in the same excel workbook in S3 bucket.
Dataframe df looks as below:
Below is my code:
today = datetime.datetime.now().strftime('%m_%d_%Y_%H_%M_%S')
components=["COMP1","COMP2","COMP3"]
filename = 'auto_export_'+today
for comp in components:
df1= df[df['component']==comp]
print(comp)
print(df1)
with io.BytesIO() as output:
with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
df1.append_df_to_excel(writer, sheet_name=comp, index=False)
data = output.getvalue()
s3 = boto3.resource('s3')
s3.Bucket('mybucket').put_object(Key='folder1/'+filename+'.xlsx', Body=data)
This is generating the excel file correctly but writing only COMP3 data into it. It is not writing COMP1 and COMP2 sheets. Any guidance on how to fix this problem?