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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With