Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't convert Matrix to DataFrame JULIA

How can i convert a matrix to DataFrame in Julia?

I have an 10×2 Matrix{Any}, and when i try to convert it to a dataframe, using this:

df2 = convert(DataFrame,Xt2)

i get this error:

MethodError: Cannot `convert` an object of type Matrix{Any} to an object of type DataFrame
like image 872
jvm.97 Avatar asked Sep 06 '25 23:09

jvm.97


1 Answers

Try instead

df2 = DataFrame(Xt2,:auto)

You cannot use convert for this; you can use the DataFrame constructor, but then as the documentation (simply type ? DataFrame in the Julia REPL) will tell you, you need to either provide a vector of column names, or :auto to auto-generate column names.

Tangentially, I would also strongly recommend avoiding Matrix{Any} (or really anything involving Any) for any scenario where performance is at all important.

like image 135
cbk Avatar answered Sep 11 '25 03:09

cbk