Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python detect system default decimal separator character (Pandas)

In my software user can load different types of a dataset using Pandas. if the software was installed on windows with English locale where the decimal separator symbol is dot (.) I will pass this char to for example read_csv function. like:

df = pd.read_csv("example.csv", decimal='.')

but it can also be installed on, for example, German locale PC where the decimal separator is the comma (,). I can get the current local using:

import locale
locale.getdefaultlocale()

but it's also possible that in german local the separator is the dot (.). Now the question is how can I explicitly know what is the decimal separator character in python so that I can parse the dataset correctly?

like image 975
M.Armoun Avatar asked Aug 08 '26 13:08

M.Armoun


1 Answers

I am so stupid. it was right in the documentation

locale.localeconv()["decimal_point"]
like image 96
M.Armoun Avatar answered Aug 10 '26 02:08

M.Armoun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!