3
我想讀一個CSV文件作爲這樣一個矩陣:如何將csv文件中的字符串列表轉換爲浮點型?
import csv
with open("data.csv", "r") as file:
table = [line for line in csv.reader(file)]
for line in table:
print(line)
但是,我需要在列表中的內容轉換爲浮動。我試圖轉換使用
table = [int(x) for x in table]
浮動然而這出來作爲一個錯誤
TypeError: int() argument must be a string or a number, not 'list'
怎樣才能解決這個問題?
int(e)for e in lst –
請修復您的代碼格式 – inspectorG4dget