# Cannot convert an object of type DataFrame to an object of type Array

**URL:** <https://discourse.julialang.org/t/cannot-convert-an-object-of-type-dataframe-to-an-object-of-type-array/61598>\
**Category:** General Usage\
**Tags:** question, dataframes, convert\
**Created:** [May 21, 2021, 5:11pm UTC](https://discourse.julialang.org/t/cannot-convert-an-object-of-type-dataframe-to-an-object-of-type-array/61598 "2021-05-21T17:11:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![valperez](https://avatars.discourse-cdn.com/v4/letter/v/e79b87/32.png) [@valperez](https://discourse.julialang.org/u/valperez)\
**Post date:** [May 21, 2021, 5:11pm UTC](https://discourse.julialang.org/t/cannot-convert-an-object-of-type-dataframe-to-an-object-of-type-array/61598/1 "2021-05-21T17:11:07Z")

</div>

Hi,  
I have a Data Frame that I want to convert into an Array but Julia gives me the following error:  
MethodError: Cannot `convert` an object of type  
DataFrame to an object of type  
Array

I believe that there has something to do with the new version of the DataFrames package but I can’t find anything in the documentation. I would appreciate any help.

Ps. I can’t upload the data because it’s confidential but would appreciate any help 🙂

---

<div class="post-metadata">

**Author:** ![chris-b1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chris-b1/32/14165_2.png) [@chris-b1](https://discourse.julialang.org/u/chris-b1)\
**Post date:** [May 21, 2021, 7:42pm UTC](https://discourse.julialang.org/t/cannot-convert-an-object-of-type-dataframe-to-an-object-of-type-array/61598/2 "2021-05-21T19:42:13Z")

</div>

You’ll get more help if you can reduce your problem down to a minimal example. But what you may want is passing your dataframe to the `Matrix` constructor, which will convert it to a 2d array, possibly of an abstract type if necessary

```julia
julia> df = DataFrame(a=[1, 2], b=[3, 4])
2×2 DataFrame
 Row │ a b     
     │ Int64 Int64 
─────┼──────────────
   1 │ 1 3
   2 │ 2 4

julia> Matrix(df)
2×2 Matrix{Int64}:
 1 3
 2 4

julia> df = DataFrame(a=[1, 2], b=["some", "strings"])
2×2 DataFrame
 Row │ a b       
     │ Int64 String  
─────┼────────────────
   1 │ 1 some
   2 │ 2 strings

julia> Matrix(df)
2×2 Matrix{Any}:
 1 "some"
 2 "strings"

```

---

<div class="post-metadata">

**Author:** ![Bishal\_Mohari](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bishal_mohari/32/26153_2.png) [@Bishal\_Mohari](https://discourse.julialang.org/u/Bishal_Mohari)\
**Post date:** [June 16, 2021, 12:33pm UTC](https://discourse.julialang.org/t/cannot-convert-an-object-of-type-dataframe-to-an-object-of-type-array/61598/3 "2021-06-16T12:33:08Z")

</div>

Thanks! this helped
