Cleaning Data

I am downloading a CSV file that has financial data. So it has dollar signs, commas, decimal points, pluses, and minuses. I’ve been trying to remove this extra stuff so I can using floating point arithmetic, but I can’t get anywhere.

a = [“$123.00”, “$1,234.56”, “-$123.45”]

julia> replace!(a, “,” => “”)
3-element Vector{String}:
“$123.00”
“$1,234.56”
“-$123.45”

The comma remains. I get the same results (no change) trying to remove the $.,- symbols. There’s got to be an easy way to handle this.


julia> a = [raw"$123.00", raw"$1,234.56", raw"-$123.45"]
       
       parse.(Float64, replace.(a, "," => "", raw"$" =>""))
3-element Vector{Float64}:
  123.0
 1234.56
 -123.45

The reason this didn’t work is because a doesn’t contain an element ",".

You want to perform this replace for each element of a, not on a itself

1 Like

Thanks. I meant to write r"," not “,”.