I have a single dimensional Array output (as shown below) and need to be converted to DataFrame.
x = rand(4)
4-element Array{Float64,1}:
0.951252
0.936421
0.773268
0.207913
p = convert(DataFrame, x) // Why this doesn't work ?
This results in:
MethodError: Cannot
convertan object of type Array{Float64,1} to an object of type DataFrames.DataFrame This may have arisen from a call to the constructor DataFrames.DataFrame(...), since type constructors fall back to convert methods.
Why this doesn't work ?
I think that DataFrame needs column name. You could use for example this:
julia> df = DataFrame(column_name = x)
4×1 DataFrames.DataFrame
│ Row │ column_name │
├─────┼─────────────┤
│ 1 │ 0.349747 │
│ 2 │ 0.718652 │
│ 3 │ 0.0984634 │
│ 4 │ 0.553987 │
If you have problem with julia then good start is to use help:
julia>?DataFrame
if you press ? as first character prompt is changed to
help?> DataFrame
after pressing enter you could see help in this case with examples.
Maybe some tutorial. For example wikibook could help too.
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