1

I am working with a big set of data, which has 9 rows (B3:J3 in column 3) and stretches until B1325:J1325. Using Python and the Openpyxl library, I need to get the biggest and second biggest value of each row and print those to a new field in the same row. I already assigned values to single fields manually (headings), but cannot seem to even get the max value in my range automatically written to a new field. My code looks like the following:

for row in ws.rows['B3':'J3']:
sumup = 0.0
for cell in row:
    if cell.value != None:
    .........

It throws the error:

for row in ws.rows['B3':'J3']:
TypeError: 'generator' object has no attribute '__getitem__'

How could I get to my goal here?

vestland
  • 55,229
  • 37
  • 187
  • 305
Homerun_
  • 13
  • 5

1 Answers1

0

You can you iter_rows to do what you want.

Try this:

for row in ws.iter_rows('B3':'J3'):
    sumup = 0.0
    for cell in row:
        if cell.value != None:
        ........

Check out this answer for more info: How we can use iter_rows() in Python openpyxl package?

Community
  • 1
  • 1
Tom
  • 304
  • 4
  • 9