I can't seem to find the option to set the decimal point for floats (".", or ",") when WRITING a DataFrame to a csv file. (Reading is no problem.) My task/problem: I'm publishing a program/script and want all users independent of their OS and language settings to use it and specifically produce a csv output with THE decimal point setting as given in "locale.localeconv()["decimal_point"]". The "float_format" option has not worked for me. Do I need to convert every float to a string and replace the "." with ","? If this is posted somewhere else please excuse my mistake and provide me with the proper link.
Thank you very much for your time and effort!!
Not going to be that efficient, but does the job (just to_csv) after)
In [29]: df = DataFrame(dict(A = [1.5,2.5], B = [2.5,3.0]))
In [30]: df
Out[30]:
A B
0 1.5 2.5
1 2.5 3.0
In [31]: df.applymap(lambda x: str(x).replace('.',','))
Out[31]:
A B
0 1,5 2,5
1 2,5 3,0
This should be a bit faster (needs at least 0.12)
In [37]: df.applymap(str).replace(r'\.',',',regex=True)
Out[37]:
A B
0 1,5 2,5
1 2,5 3,0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With