0

I am looking for the correct way to change the comma decimal separator to the dot decimal separator.

How can you change the decimal separator from comma , to dot . with Python Pandas?

import pandas as pd

df = pd.read_csv("some.csv", quotechar='"', decimal=",")
decmark_reg = re.compile('(?<=\d),(?=\d)')          #replace all commas with dots
decmark_reg.sub('.', result) # IS THIS CORRECT WAY TO CHANGE DECIMAL Separator?
...
result.to_csv(fileName, sep=',', encoding='utf-8', quotechar='"')

[Apparently a solution] to change the , decimals to the . decimals

import pandas as pd

df = pd.read_csv("some.csv", quotechar='"', decimal=",")
df.to_csv(fileName, sep=',', encoding='utf-8', quotechar='"', decimal='.')
hhh
  • 50,788
  • 62
  • 179
  • 282
  • 1
    Seen [Convert commas to dots within a Dataframe](https://stackoverflow.com/questions/31700691/convert-commas-to-dots-within-a-dataframe)? – Zero Oct 02 '17 at 14:39
  • 1
    `result.to_csv(fileName, sep=',', encoding='utf-8', quotechar='"', decimal=',')` – cs95 Oct 02 '17 at 14:41
  • @cᴏʟᴅsᴘᴇᴇᴅ so `read_csv()` has the initial decimal separator (here comma) while the `to_csv` has the wanted decimal separator (here dot). Did I understand this right? – hhh Oct 02 '17 at 14:44
  • The sep refers to the column separator. I assume your initial csv has a different separator from a comma. – cs95 Oct 02 '17 at 14:45
  • @cᴏʟᴅsᴘᴇᴇᴅ initial separator is the comma `,` in the file while the wanted separator in the output is the dot `.`. Is the solution in the Q correct? – hhh Oct 02 '17 at 14:47

0 Answers0