我对Python比较陌生,我正在尝试计算填充数据的excel表中的空单元格数。为了测试程序,我一直在删除一些值,以便单元格为空:我的代码在
之下import xlrd
import pandas as pd
import openpyxl
df = pd.read_excel('5train.xls')
workbook = xlrd.open_workbook('5train.xls')
worksheet = workbook.sheet_by_name('5train')
#Task starts here
empty = 0
row_data = worksheet.nrows - 1
row = 0
cell = 0
while row < row_data:
if worksheet.cell(0, 0).value == xlrd.empty_cell.value:
empty += 1
cell += 1
else:
pass
row += 1
print("Number of empty cells in data sheet:", empty)
但是,无论我清空多少个单元格,代码都会始终打印“数据表中的空单元数:0”。有什么指针吗?谢谢!