Type Nothing has no field match

I’m learning Linear Regression model with housing dataset from Kaggle.

Dealing with a problem to extract int or float from string make me some confusing.

# rename columns
renamed_df = rename(df2, Dict("Diện tích" => "Area", "Giá/m2" => "Price/m2"))
# convert "," => "." in string
comma_to_dot_column = map(x -> replace(x, "," => "."), renamed_df[:, "Price/m2"])
# extract int or float from string
for i in comma_to_dot_column
    @show typeof(match(r"[+-]?\d+(\.\d+)?", i).match)
end

The for loop returns error: type Nothing has no field match despite the fact that all regex match in the column existing in RegexMatch datatype.

I migrate from Python to Julia so maybe missing some important concept about Julia Datatype in this code

in this line, the .match would throw an error before you can show anything, so I suggest you do this:

m = match(r"[+-]?\d+(\.\d+)?", i)
if isnothing(m)
    @show i
end
1 Like