0

What is the proper way to replace dots to strings as the code below?

s = pd.Series(['1,1', '2,2', '3,3', '4,4', '5,5'])

Also, why this code below does not work?

s.replace({',':'.'})
  • This code will never work because different countries have different formatting rules. What happens if the value is `1,000.12`? You need to parse the strings into numbers using the correct locale – Panagiotis Kanavos May 10 '22 at 12:31
  • The "duplicate" is completely wrong and actually harmful. Numeric format problems can't be solved by arbitrary character replacements – Panagiotis Kanavos May 10 '22 at 12:32
  • @PanagiotisKanavos - can you check new dupes? – jezrael May 10 '22 at 12:39
  • @jezrael please remove the replacement link. Things like this cause serious bugs (and SO questions). If it wasn't for China I could say that most of the world [doesn't* use `.` as the decimal separator](https://en.wikipedia.org/wiki/Decimal_separator#Usage_worldwide). And then there are weird cases like India (grouping by 2/3 digits) or South Africa where the official standard is spaces and comma but most people use comma and dot – Panagiotis Kanavos May 10 '22 at 12:52
  • @jezrael just for fun check [this thread](https://answers.microsoft.com/en-us/windows/forum/all/south-africas-region-settings-are-wrong-how-can-i/1ee9cdc0-4e8c-415f-912f-1bf0b4ab4a7d) where South African users complain about the Windows settings only to realize at the end their own country's official settings are different: `To suddenly find (be reminded) that the South African standard is a ',' decimal separator (in numbers and currency) is a bit of a shock.` – Panagiotis Kanavos May 10 '22 at 12:56
  • @PanagiotisKanavos - in Slovakia is decimal separator `,` thousands is space.. :( – jezrael May 10 '22 at 12:57

0 Answers0