Pandas convert numbers with a comma instead of the point for the decimal separator from objects to numbers

ninazzo

Im my dataframe I have a column with numbers a format with the comma as separator, like 0,5 and the data type inferred is object. I need to convert them to numbers, but when I try df['ColumnName'] = pd.to_numeric(df['ColumnName']) I get the following exception:

ValueError                                Traceback (most recent call last)
pandas/_libs/lib.pyx in pandas._libs.lib.maybe_convert_numeric()

ValueError: Unable to parse string "2,55"

I tried looking on google and so, but couldn't find a solution. The to_numeric method's signature does not allow to specify a separator.

Any ideas on how could I fix the problem?

Quang Hoang

You can replace , with .:

df['ColumnName'] = pd.to_numeric(df['ColumnName'].str.replace(',', '.'))

On the other note, if you read the data with pd.read_csv, there's an option decimal=','.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Pasting decimal numbers in excel / comma and point decimal separator

From Dev

How to convert floating point decimal separator from dot to comma in Javascript

From Dev

Show comma instead of point as decimal separator

From Dev

Show comma instead of point as decimal separator

From Dev

Parsing numbers with a comma decimal separator in JavaScript

From Dev

Add comma separator to a numbers with 2 decimal points

From Dev

Google form regex for numbers with comma as decimal separator

From Dev

Convert floating point numbers to decimal numbers

From Dev

Searching for numbers with a comma as a decimal point in an array

From Dev

Decimal comma instead of decimal point

From Dev

Getting numbers behind decimal separator

From Dev

bc: decimal separator comma vs. point

From Dev

Forcing decimal point instead of comma

From Dev

Convert decimal numbers from string to double

From Dev

Convert a double to 2 decimal places with comma separator

From Dev

Convert a double to 2 decimal places with comma separator

From Dev

In R print decimal comma instead of decimal point

From Dev

Variable using decimal comma instead of decimal point

From Dev

convert decimal numbers to ascii

From Dev

convert decimal numbers to ascii

From Dev

How does computer convert floating point numbers to decimal string?

From Dev

How does computer convert floating point numbers to decimal string?

From Dev

Match numbers with decimal separator inside a string

From Dev

Make decimal point to whole numbers

From Dev

Make decimal point to whole numbers

From Dev

JavaScript regex to accept numbers with comma separator (thousands) and dot separator (decimals)

From Dev

Extracting numbers with a decimal point from ls output in Bash

From Dev

Regex - search for numbers, preceded by a comma or quote, that have no digits before the decimal point

From Dev

Convert Octal numbers to Decimal numbers in Lex

Related Related

  1. 1

    Pasting decimal numbers in excel / comma and point decimal separator

  2. 2

    How to convert floating point decimal separator from dot to comma in Javascript

  3. 3

    Show comma instead of point as decimal separator

  4. 4

    Show comma instead of point as decimal separator

  5. 5

    Parsing numbers with a comma decimal separator in JavaScript

  6. 6

    Add comma separator to a numbers with 2 decimal points

  7. 7

    Google form regex for numbers with comma as decimal separator

  8. 8

    Convert floating point numbers to decimal numbers

  9. 9

    Searching for numbers with a comma as a decimal point in an array

  10. 10

    Decimal comma instead of decimal point

  11. 11

    Getting numbers behind decimal separator

  12. 12

    bc: decimal separator comma vs. point

  13. 13

    Forcing decimal point instead of comma

  14. 14

    Convert decimal numbers from string to double

  15. 15

    Convert a double to 2 decimal places with comma separator

  16. 16

    Convert a double to 2 decimal places with comma separator

  17. 17

    In R print decimal comma instead of decimal point

  18. 18

    Variable using decimal comma instead of decimal point

  19. 19

    convert decimal numbers to ascii

  20. 20

    convert decimal numbers to ascii

  21. 21

    How does computer convert floating point numbers to decimal string?

  22. 22

    How does computer convert floating point numbers to decimal string?

  23. 23

    Match numbers with decimal separator inside a string

  24. 24

    Make decimal point to whole numbers

  25. 25

    Make decimal point to whole numbers

  26. 26

    JavaScript regex to accept numbers with comma separator (thousands) and dot separator (decimals)

  27. 27

    Extracting numbers with a decimal point from ls output in Bash

  28. 28

    Regex - search for numbers, preceded by a comma or quote, that have no digits before the decimal point

  29. 29

    Convert Octal numbers to Decimal numbers in Lex

HotTag

Archive