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.0
numpy==1.19.0
pandas==1.0.5
python-dateutil==2.8.1
pytz==2020.1
six==1.15.0
xlrd==1.2.0
XlsxWriter==1.2.9
- Code
import logging
import io
import xlrd
import pandas as pd
import xlsxwriter
import azure.functions as func
async def main(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)
if not 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"