juliajulia-dataframe

Format string numbers into Float64 in julia dataframe


I have a dataframe with a column (column 1) that looks like this. It's a bunch of numbers that are of type string. I would like to update "column 1" or create a new column "column 1 formatted" and the type to be either string or Float64 and to have numbers look like this instead.

|Column 1|    |Updated or new column|
|String  |    |Float64              |
----------    -----------------------
|400     |    |400.00               |
|120     |    |120.00               |
|37      |    |37.00                |
|1 500,00|    |1500.00              |
|166,14  |    |166.14               |
|13,95   |    |13.95                |
|1 148,18|    |1148.18              |

I have tried with replace to get rid of the "," and whitespace and parse it into Float64, but I haven't getting really any closer to what I want to achive.


Solution

  • Use:

    df."Column 1 formatted" = parse.(Float64, replace.(df."Column 1", " "=>"", ','=>"."))