# How to create data frame from saved vectors in julia 1.7?

**URL:** <https://discourse.julialang.org/t/how-to-create-data-frame-from-saved-vectors-in-julia-1-7/79046>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [April 5, 2022, 1:23pm UTC](https://discourse.julialang.org/t/how-to-create-data-frame-from-saved-vectors-in-julia-1-7/79046 "2022-04-05T13:23:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [April 5, 2022, 1:23pm UTC](https://discourse.julialang.org/t/how-to-create-data-frame-from-saved-vectors-in-julia-1-7/79046/1 "2022-04-05T13:23:04Z")

</div>

Hello,  
I have a matrix `features` 2 columns 2000 rows and I would like to convert it into a data frame.  
I tried with:

```julia
julia> df = DataFrames(Time = features[:,1], Amount = features[:,2])
ERROR: MethodError: objects of type Module are not callable
Stacktrace:
 [1] top-level scope
   @ none:1

```

How do I create a data frame from vectors in Julia?

PS: to note that

```julia
julia> using DataFrames
julia> df = Dataframe()
ERROR: UndefVarError: Dataframe not defined
Stacktrace:
 [1] top-level scope
   @ none:1

```

---

<div class="post-metadata">

**Author:** ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)\
**Post date:** [April 5, 2022, 1:26pm UTC](https://discourse.julialang.org/t/how-to-create-data-frame-from-saved-vectors-in-julia-1-7/79046/2 "2022-04-05T13:26:52Z")

</div>

DataFrame

```julia
julia> features = [1 2; 3 4]
2×2 Matrix{Int64}:
 1 2
 3 4

julia> df = DataFrame(Time=features[:,1], Amount=features[:,2])
2×2 DataFrame
 Row │ Time Amount 
     │ Int64 Int64  
─────┼───────────────
   1 │ 1 2
   2 │ 3 4

```

---

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [April 5, 2022, 1:30pm UTC](https://discourse.julialang.org/t/how-to-create-data-frame-from-saved-vectors-in-julia-1-7/79046/3 "2022-04-05T13:30:24Z")

</div>

> [@lawless-m](#):
>
> `df = DataFrame(Time=features[:,1], Amount=features[:,2])`

so it was the extra ‘s’. Thanks

---

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [April 5, 2022, 1:45pm UTC](https://discourse.julialang.org/t/how-to-create-data-frame-from-saved-vectors-in-julia-1-7/79046/4 "2022-04-05T13:45:20Z")

</div>

Addendum: if I wanted to add a column, I understand I can use df.newColumn. I have an object that I believe is a vector, but when I add it to the data frame I get the repetition of the vector on each row of the dataframe:

```julia
julia> O
"[active, passive, passive, delayed_active, active, active, active, passive, passive, active, active, passive, active, ### to note that REPL does not say "vector"
julia> df.Outcome = O
ERROR: ArgumentError: It is only allowed to pass a vector as a column of a DataFrame. Instead use `df[!, col_ind] .= v` if you want to use broadcasting.
Stacktrace:
 [1] setproperty!(#unused#::DataFrame, col_ind::Symbol, v::String)
   @ DataFrames ~/.julia/packages/DataFrames/ORSVA/src/dataframe/dataframe.jl:650
 [2] top-level scope
   @ none:1

julia> df.Outcome = [O]
ERROR: ArgumentError: New columns must have the same length as old columns
Stacktrace:
 [1] insert_single_column!(df::DataFrame, v::Vector{String}, col_ind::Symbol)
   @ DataFrames ~/.julia/packages/DataFrames/ORSVA/src/dataframe/dataframe.jl:610
 [2] setindex!
   @ ~/.julia/packages/DataFrames/ORSVA/src/dataframe/dataframe.jl:640 [inlined]
 [3] setproperty!(df::DataFrame, col_ind::Symbol, v::Vector{String})
   @ DataFrames ~/.julia/packages/DataFrames/ORSVA/src/dataframe/dataframe.jl:646
 [4] top-level scope
   @ none:1

julia> df.[!, Outcome] .= O
ERROR: MethodError: no method matching getproperty(::DataFrame, ::Expr)
Closest candidates are:
  getproperty(::AbstractDataFrame, ::AbstractString) at ~/.julia/packages/DataFrames/ORSVA/src/abstractdataframe/abstractdataframe.jl:379
  getproperty(::AbstractDataFrame, ::Symbol) at ~/.julia/packages/DataFrames/ORSVA/src/abstractdataframe/abstractdataframe.jl:378
  getproperty(::Any, ::Symbol) at ~/src/julia/share/julia/base/Base.jl:42
  ...
Stacktrace:
 [1] dotgetproperty(x::DataFrame, f::Expr)
   @ Base ./Base.jl:45
 [2] top-level scope
   @ none:1

```

I think here the problem is that O is not a vector (although it came from one) and I need to split O at the commas…

---

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [April 5, 2022, 1:54pm UTC](https://discourse.julialang.org/t/how-to-create-data-frame-from-saved-vectors-in-julia-1-7/79046/5 "2022-04-05T13:54:58Z")

</div>

Yes, solved it with `O = split(O, ",")`
