Python Pandas:在Pandas Dataframe中将逗号小数改为点小数的正确方法吗?

时间:2017-10-02 14:38:36

标签: python pandas dataframe decimal

我正在寻找将逗号小数点分隔符更改为点小数点分隔符的正确方法。

如何使用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='.')

0 个答案:

没有答案