Skip to content
Advertisement

How to convert object to float in Pandas?

I read a csv file into a pandas dataframe and got all column types as objects. I need to convert the second and third columns to float.

I tried using

JavaScript

but got NaN.

Here’s my dataframe. Should I need to use some regex in the third column to get rid of the “R$ “?

enter image description here

Advertisement

Answer

Try this:

JavaScript
JavaScript

Output:

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