Skip to content
Advertisement

Converting string in a Pandas data frame to float

I have the following data frame:

JavaScript

In order to calculate with the second column named “Marktwert”, I have to convert the string as a float, the sting has German format, that means the decimal point is a comma and the thousands separator is a dot. The number 217.803,37 has the datatype object.

If I try to convert using the code

JavaScript

I get the error

JavaScript

Can anyone help me out pls?

Advertisement

Answer

In case you’re reading the data from a file, many of Pandas’ file readers like pandas.read_csv() have decimal and thousands arguments for exactly this case.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement