Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
Average Excel Columns

I am trying to average out values within a column at a certain range. I tried listing out the range as a tuple then for looping to be able to get the cell value. I then created a variable for the average but get the error 'TypeError: 'float' object is not iterable.

range1 = ws["A2":"A6]
for cell in range1:
    for x in cell:
        average = sum(x.value)/len(x.value)
        print(average)
about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Python and the Openpyxl API makes this kind of thing very easy.

rows = ws.iter_rows(min_row=2, max_row=6, max_col=1, values_only=True)
values = [row[0] for row in rows]
avg = sum(values) / len(values)

But you should probably check that the cells contain numbers, otherwise you'll see an exception.

about 4 years ago · Santiago Trujillo Relatório

0

Something like this will get you the mean of the cells.

import openpyxl as op

def main():
    wb = op.load_workbook(filename='C:\\Users\\####\\Desktop\\SO nonsense\\Book1.xlsm')
    
    range1 = wb['Sheet1']['A2:A6']
    cellsum = 0
    for i, cell in enumerate(range1, 1): 
        print(i)
        cellsum += cell[0].value
        
    print(cellsum / i)
main()
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda