2
I am a beginner in Python and am trying to make a script to sum all the values of an excel column and write the sum value in the spreadsheet. I’m using the Python xlrd and xlwt packages. The code works well for the first column, but from the second no longer works, it always reports value 0. I hope someone more experienced can help me.
Thank you!
import xlwt
import xlrd
workbook_page = xlrd.open_workbook('page_level.xlsx')
worksheet_page = workbook_page.sheet_by_name('Daily External Referrers')
num_rows = worksheet_page.nrows - 1
curr_row = 0
num_cols = worksheet_page.ncols - 1
curr_col = 1
soma = 0
while curr_col < num_cols:
curr_col = curr_col + 1
while curr_row < num_rows:
curr_row = curr_row + 1
row = (worksheet_page.cell_value(curr_row, curr_col))
if isinstance (row, float):
soma = soma + row
else:
pass
worksheet_page.write(num_rows+1, curr_col, soma)
worksheet_page.save('page_level.xlsx')