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

457
Vistas
Change commas to dots in Excel with Python

I print the tables I scanned from the internet with Selenium to Excel. However, this table contains values such as "15,300". I would like to print these values as "15,300" or "15.3" and change the cells that are normally "1.022" to "1022". And I add schedule for every 5 mins.

In short, I want to remove the dot from the dotted values, and convert the comma to a dot.

I take the whole table as a class and then split it into parts. Here is my code: (Unfortunately, since it is company data, I can only share a certain part.)

driver.get(urlTarget)
    a=driver.find_element_by_class_name("dataTable").text
    #print(a)
    x = a.split('\n')
    x[0] = "Mak.No. AEF% SEF% DAS% YLW% YF/Y MIS% RTI% NDOF PRKG(kg) DOF% NCOP YEF% YEF-A% YEF-B% FBE% FBE-A% FBE-B% SBE% SBE-A% SBE-B% NCTB NT/T"
    for i in range (len(x)-1):
        if i != 0:
            x[i]=x[i+1]
    #print(x)
    workbook = xlsxwriter.Workbook('C:/Users/...xxx.xlsx')
    worksheet = workbook.add_worksheet()

In the code above, I deleted the column names and the places I wanted to delete. The place where the actual process will pass is in the code below.

    row = 0
    column = 0
    b=x[:(len(x)-1)]    
    for i in b:
        c=i.split()
        column=0
        for item in c :
            worksheet.write(row, column, item)
            column+=1
        row += 1
    workbook.close()

This writes the table to Excel. But I need changes. When I use item=item.str.replace(',','.') in the for loop, it will returns error that 'str' object has no attribute 'str'.

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

first convert the number to string and if it is already string then don't use ".str"

item = item.replace(',','.')

or

item = str(item).replace(',','.')
about 4 years ago · Santiago Trujillo Denunciar

0

I believe you're on the wrong track here: the dots and commas you're dealing with are decimal and thousand separators. In order to work with them, you might alter the format of your cells, as shown in this dialog box for one particular cell:

Excel cell formatting

There also are the regional settings of your Windows computer:

Windows regional settings, number formatting

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