-1

I have my data in an excel file and I want to python to get the number of occupied cells in a specific row. How can I do that?

For instance, if I want to know how many columns are occupied with data in row 5, how would I achieve that?

PS: The cells are occupied with strings Notice how some rows have more data than some (click here to see image)

Ian Rajkumar
  • 149
  • 1
  • 8

1 Answers1

0

you can iterate on the row:

def get_filled_cols(row_obj):
    counter = 0
    for c in row_obj:
        if c.value != None:
            counter += 1
    return counter

now you can check for row, 5 for example:

get_filled_cols(ws[5])
meni181818
  • 1,103
  • 1
  • 7
  • 11