Azure Function - Pandas Dataframe To Excel, Write To Outputblob Stream
Am trying to write a DataFrame to an outputBlob from an Azure Function. I'm having trouble figuring out which io stream to use. My function looks like this: import io impor
Solution 1:
If you want to save DataFrame as excel to Azure blob storage, please refer to the following example
- SDK
azure-functions==1.3.0numpy==1.19.0pandas==1.0.5python-dateutil==2.8.1pytz==2020.1six==1.15.0xlrd==1.2.0XlsxWriter==1.2.9
- Code
import logging
import io
import xlrd
import pandas as pd
import xlsxwriter
import azure.functions as func
asyncdefmain(myblob: func.InputStream,outputblob: func.Out[func.InputStream]):
logging.info(f"Python blob trigger function processed blob \n"f"Name: {myblob.name}\n")
input_file = xlrd.open_workbook(file_contents = myblob.read())
df = pd.read_excel(input_file)
ifnot df.empty:
xlb=io.BytesIO()
writer = pd.ExcelWriter(xlb, engine= 'xlsxwriter')
df.to_excel(writer,index=False)
writer.save()
xlb.seek(0)
outputblob.set(xlb)
logging.info("OK")
Post a Comment for "Azure Function - Pandas Dataframe To Excel, Write To Outputblob Stream"