我正在寻找将逗号小数点分隔符更改为点小数点分隔符的正确方法。
如何使用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='"')
[显然是解决方案] 将,
小数更改为.
小数
import pandas as pd
df = pd.read_csv("some.csv", quotechar='"', decimal=",")
df.to_csv(fileName, sep=',', encoding='utf-8', quotechar='"', decimal='.')