這是一個奇怪的錯誤,之前在
當我加載它按預期運行的應用程式時,我可以添加行,但是當我上傳 csv 檔案時,我收到以下錯誤:
File "C:\Users\harry\OneDrive\Documents\coding\fypWebApp\dashApp\app.py", line 255, in update_output
zip(list_of_contents, list_of_names, list_of_dates)]
TypeError: 'float' object is not iterable
似乎問題在于 update_output 函式中的串列之一。另外,我在 VSCode 中收到以下通知。

只有當我將代碼從檔案中提取到獨立檔案中時(如下圖所示),只有當我將代碼輸入到我的代碼中時,才會出現此通知。

我不知道從哪里開始解決這個問題,而且似乎需要對 Dash 有很好的理解才能解決。任何幫助表示贊賞。
uj5u.com熱心網友回復:
經過長時間的除錯,問題是這list_of_dates是一個浮點數,表示上傳檔案的最后修改。回呼中有一個串列理解,它遍歷這個浮點數,這對遍歷一個數字沒有意義,最終會引發錯誤。要解決這個問題,您應該做的就是將回呼函式替換為以下內容:
def update_output(list_of_contents, list_of_names, list_of_dates):
if list_of_contents is not None:
children = [parse_contents(list_of_contents, list_of_names, list_of_dates)]
return children
在函式內部parse_contents,我添加了delimiter=";"正確讀取 CSV 檔案的方法。
if 'csv' in filename:
# Assume that the user uploaded a CSV file
df = pd.read_csv(
io.StringIO(decoded.decode('utf-8')), delimiter=";") #<-- this line.
最后,我縮小了上表的大小以顯示 CSV 檔案的表。
輸出

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/520950.html
標籤:PythonCSV破折号
