Reputation: 4987
How to rename all values in specific column in dataframe? I was thinking that something like this should work:
dfProducts[:StandardCost] = replace(dfProducts[:StandardCost], "£", convert(UTF8String,""))
But it didnt.
replace
has no method matching replace(::DataArray{UTF8String,1}, ::UTF8String, ::UTF8String)
In general the values in this column are in format "£0,000.00" and I was thinking to replace the "£" and "," and convert them to Float type because I need to multiply them with another column.
Upvotes: 0
Views: 183
Reputation: 2718
You can use map
:
dfProducts[:StandardCost] = map(x->replace(x, "£", convert(UTF8String,"")), dfProducts[:StandardCost])
EDIT: You can extend the method if you want to keep this workaround somewhere else (ie "maybe improve readability")
Base.replace(a::DataArray{UTF8String,1}, s::UTF8String, r::UTF8String) = map(x->replace(x, s, r),a)
#...
dfProducts[:StandardCost] = replace(dfProducts[:StandardCost], "£", convert(UTF8String,""))
Do mind that neither method is optimal compute-wise or continuous-memory-alloc'd-wise, but I guess that's out of the scope of the question
Upvotes: 1