How to convert an "any" column in a dataframe containing strings and floats?

I’m trying to convert a column of type “Any” in my dataframe to a column of type “Float64”. It seems that there are float values and string values in the column.

First I tried:

df[!, :column2] = tryparse.(Float64, df[:, :column2])

Which yielded the following error:
ERROR: LoadError: MethodError: no method matching tryparse(::Type{Float64}, ::Float64)

I then tried computing my correlation:

my_correlation = cor(df.column1, df.column2)

Which yielded the following error:
ERROR: LoadError: MethodError: no method matching /(::String31, ::Int64)

It seems when I use tryparse() I run into a Float64 value and get an error. When I don’t try to convert the strings and just run my correlation, I end up getting an error because you cannot calculate a Pearson correlation with strings. Is there a better way to go about parsing the strings?

it’s already Float64

If it is of type Float64, why is my code returning the second error when I try to calculate my correlation?

column1 and column2 are not the same column as my_column

Sorry, I tried to edit the post so that column2 is in the first code snippet. Can you not see that edit? It should look like:

df[!, :column2] = tryparse.(Float64, df[:, :column2])

I also tried:

df[!, :column1] = tryparse.(Float64, df[:, :column1])

and got the error: ERROR: LoadError: MethodError: no method matching tryparse(::Type{Float64}, ::Float64)

You’re parsing my_column, but it’s already floats. You’re not using my_column to do correlation calculations

Apologies, I’ve fixed the typos!

I think it would help if you at least posted a few rows from your dataframe, and include the headers

julia> df
3×2 DataFrame
 Row │ a      b
     │ Int64  Int64
─────┼──────────────
   1 │     1      3
   2 │     2      4

Also you might get a better grasp of your situation if you used parse instead of tryparse