I have a Azure Function. From Postman, I'm uploading an excel file with name templateFile
, using form data. Now I want to convert the excel file to a pandas dataframe
.
This is what data in the excel file looks like:
BookId Title Author YearOfPublication
1 One Arranged Murder Chetan Bhagat 2020
This is what I've tried until now, but I got not idea how to move forward.
import pandas as pd
import azure.functions as func
def main(req: func.HttpRequest) -> func.HttpResponse:
templatefile = req.files['templatefile']
templateStream = templatefile.stream
text = templateStream.read().decode('utf-8')
And also when I try to decode the bytes, it's not happening. I've tried both utf-8
and ascii
. Nothing works.
Any suggestions or ideas will be helpful.
CodePudding user response:
Try this:
df_test = pd.read_excel(req.files['templatefile'].read(), engine='openpyxl')