jvm.97
jvm.97

Reputation: 247

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

Upvotes: 4

Views: 1420

Answers (1)

cbk
cbk

Reputation: 4370

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.

Upvotes: 6

Related Questions