Replace Character in a column

Hi everybody,

I am using DataFrames to work with a CVS file. However, the file includes both numbers and characters.
Then DataFrames defined the columns that have only Number to be “Float64” type, and the columns that have both Numbers and Characters to be “String”.
The sample of the column as the attached figure.

I need to convert the column assigned as “String” to be “Float64”, but parse(Float64, “String”) does not work.
I have two questions:

  1. How can I remove the row contain text “#VALUE!” in the column, and then convert the remain to Foat64?

  2. Is it possible to replace the text “#VALUE!” by the “number” in the closest row? If it is possible, please teach me how to do?

Thanks you very much!

i dont use a lot of dataframes, but maybe pre-processioning the CSV could work, replacing #VALUE! by an empty string

Something like this would work for #1.

[ parse(Float64,x) for x in skipmissing(df[:Loc3]) if x !="#VALUE!"]

2 Likes

Hi Daniel,

Thank you very much!
It is work!
But the result is remained only the column [:Loc3] after remove the “#VALUE!”
How I can keep the other columns in the table with removed on the rows having “#VALUE!”.
Thank you.

Use the missingstring = "#VALUE" argument when you readd it in with CSV.read. Then it’s easy to replace all missing values in your column, e.g. with ifelse.

2 Likes