Parsing strings into Float32 handling empty values

Hi, I’m trying to get a Float32 dataframe from SQL data extracted as strings

df[!, "Equity"] = parse.(Float32, df[!, "Equity"])  # Convert to Float32

But I’ve empty rows, therefore I’ve

ERROR: ArgumentError: cannot parse "" as Float32

I’ve tried different type of methods to handle that, as to allow NaN or missing values, haven’t found yet something that works. Figured that someone must know how to do it here as it seems a pretty trivial problem.

thank you

You could define e.g.

myparse(s) = isempty(s) ? missing : parse(Float32, s)

and then do myparse.(df[!, "Equity"]), for example.

1 Like