我的剧本在接一个不该接的字符串,我得到ValueError: could not convert string to float: for line list_col.append(float(row[c].strip('"'))) in the code belowwith open(fileTwoName) as f:
reader = csv.reader(f, delimiter=",")
fileTwoColumnNames = next(reader)
output_column .extend(fileTwoColumnNames[2:-1])
number_of_columns = len(fileTwoColumnNames)-2
for c in range(2,number_of_columns+2):
list_col = []
f.seek(1)
next(reader)
for row in reader:
list_col.append(float(row[c].strip('"')))
list_col_name_wise = []
for k in range(0, len(number_eng)):
list_col_name_wise.append(sum(list_col[start_row[k] - 1:start_row[k] - 1 + 1- total_case [k]]))
data.append(list_col_name_wise)
我通过添加if list_col == str:
list_col.append(float(row[c].strip('"'))) `
所有输出都正常,但我需要我的data列表作为浮点输出。我有办法同时考虑str和float吗?