Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

454
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!