I'm writing some script on Azure function with python, which want to handle the csv file which was upload to blob storage.
The coding I tested pass in local, but it got error on Azure function.
Result: Failure Exception: IndexError: list index out of range Stack: File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 355, in handle_invocation_request call_result = await self.loop.run_in_executor( File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(self.args, *self.kwargs) File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 542, in _run_sync_func return func(**params) File "/home/site/wwwroot/csvhandler/init.py", line 28, in main text1=list1[0]
Not quite sure why it said list index out of range Stack, the list index should begin from 0..
input string
ab,cd,ef\r\n12,34,56\r\nff,gg,ee\r\n
import logging
import azure.functions as func
import pandas as pd
import numpy as np
list1=[]
def main(inputblob: func.InputStream, outputblob: func.Out[str]) -> None:
logging.info('Python Queue trigger function processed %s', inputblob.name)
str1 = inputblob.read().decode('utf-8-sig')
str1 = str1.split('\\r\\n') #split the string in list, str1="ab,cd,ef\r\n12,34,56\r\nff,gg,ee\r\n"
str1 = str1[0:-1]
for i in range(0,len(str1)): #split the list which can be written into pandas DataFrame
str2=str1[i].split(',')
list1.append(str2)
print(str1)
text1=list1[0] #verify if the element correct
text2=list1[1]
text3=list1[2]
text4=list1[3]
df = pd.DataFrame(list1[1:], columns=list1[0]) #create the dataframe
outstr=df.to_csv(index=False) #transfer the output to string
outputblob.set(outstr) #output the string in the blob
In the other hand, would anyone suggest if we can explore the edited dataframe as csv to blob storage? I can't find much info here.