Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda