我有一個Azure函式。從Postman中,我使用表單資料上傳了一個名為templateFile的Excel檔案。現在我想將這個excel檔案轉換為pandas資料框架。
這就是excel檔案中的資料的樣子:
BookId Title Author YearOfPublication
1One Arranged Murder Chetan Bhagat 2020
這是我到現在為止所做的嘗試,但我不知道該如何繼續前進。
import pandas as pd
import azure.function as func
def main(req: func.HttpRequest) -> func.HttpResponse:
templatefile = req.files['templatefile']
模板Stream = templatefile.stream
text = templateStream.read().decode('utf-8')
還有,當我試圖解碼位元組時,它沒有發生。我已經嘗試了utf-8和ascii。沒有任何效果。
任何建議或想法都會有幫助。
uj5u.com熱心網友回復:
試試這個:
df_test = pd.read_excel(req.files['templatefile'].read(), engine='openpyxl')
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/310324.html
標籤:
