尝试从Excel文件读取和求和列时出现ValueError

问题描述 投票:0回答:1

Importing excel sheet & trying to add all cell values in a single column, but keep getting ValueError. For reference, the excel sheet starts with a '', then the column name, which is 'Revenue', then the numbers. I'm assuming this error is coming from me trying to add the blank cell - Any ideas how to fix this? The blank cell is a result from a merged title cell, so I cant add a number to it ?

python valueerror
1个回答
0
投票

int('')抛出该错误。

我的建议是检查该单元格值是否包含空字符串:

s = sheet.cell_value(row,5)
is_positive = int(s) if s else 0

if is_positive>=0:
    #add logic
© www.soinside.com 2019 - 2024. All rights reserved.