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

456
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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