# How to convert DataFrame into Array{T,2}?

**URL:** <https://discourse.julialang.org/t/how-to-convert-dataframe-into-array-t-2/22487>\
**Category:** Data\
**Tags:** dataframes, arrays, convert\
**Created:** [March 29, 2019, 3:01am UTC](https://discourse.julialang.org/t/how-to-convert-dataframe-into-array-t-2/22487 "2019-03-29T03:01:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Chen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eric_chen/32/5992_2.png) [@Eric\_Chen](https://discourse.julialang.org/u/Eric_Chen)\
**Post date:** [March 29, 2019, 3:01am UTC](https://discourse.julialang.org/t/how-to-convert-dataframe-into-array-t-2/22487/1 "2019-03-29T03:01:03Z")

</div>

Let’s say I have a dataframe that only holds number or missings.  
How can I convert it to a Array{T, 2} ? Without the names / header

Thank you

```julia
using DataFrames
df = DataFrame(a=[1, 2, 3, 4, missing], b= [1, 2, 3, 4, 5])
df[:,:]

```

---

<div class="post-metadata">

**Author:** ![Ajaychat3](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@Ajaychat3](https://discourse.julialang.org/u/Ajaychat3)\
**Post date:** [March 29, 2019, 4:08am UTC](https://discourse.julialang.org/t/how-to-convert-dataframe-into-array-t-2/22487/2 "2019-03-29T04:08:20Z")

</div>

Try this one

```julia
df1=convert(Matrix,df)

```

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [March 29, 2019, 7:31am UTC](https://discourse.julialang.org/t/how-to-convert-dataframe-into-array-t-2/22487/3 "2019-03-29T07:31:44Z")

</div>

`Matrix(df)` or `Matrix{T}(df)` if you want to specify `T` that is different that is automatically inferred.

---

<div class="post-metadata">

**Author:** ![Ajaychat3](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@Ajaychat3](https://discourse.julialang.org/u/Ajaychat3)\
**Post date:** [March 29, 2019, 8:04am UTC](https://discourse.julialang.org/t/how-to-convert-dataframe-into-array-t-2/22487/4 "2019-03-29T08:04:53Z")

</div>

In the given example, Matrix{T}(df) throws an error if T is not = “Any” because one of the value is missing. Matrix(df) also works fine.

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [March 29, 2019, 8:07am UTC](https://discourse.julialang.org/t/how-to-convert-dataframe-into-array-t-2/22487/5 "2019-03-29T08:07:21Z")

</div>

You have to choose an appropriate `T` of course. Note for example that `Matrix{Union{Real, Missing}}(df)` will work fine.

---

<div class="post-metadata">

**Author:** ![Eric\_Chen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eric_chen/32/5992_2.png) [@Eric\_Chen](https://discourse.julialang.org/u/Eric_Chen)\
**Post date:** [March 29, 2019, 10:59am UTC](https://discourse.julialang.org/t/how-to-convert-dataframe-into-array-t-2/22487/6 "2019-03-29T10:59:45Z")

</div>

Great thank you!

---

<div class="post-metadata">

**Author:** ![VLonghand](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vlonghand/32/29548_2.png) [@VLonghand](https://discourse.julialang.org/u/VLonghand)\
**Post date:** [September 29, 2021, 1:10am UTC](https://discourse.julialang.org/t/how-to-convert-dataframe-into-array-t-2/22487/7 "2021-09-29T01:10:27Z")

</div>

Something I learned when trying the same thing  
If df has various types `Int` and `Float64` for me, `convert(Matrix, df)` will give an error, but `Matrix(df)` works and sets all as `Float64`.

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [September 29, 2021, 6:02am UTC](https://discourse.julialang.org/t/how-to-convert-dataframe-into-array-t-2/22487/8 "2021-09-29T06:02:17Z")

</div>

`convert(Matrix, df)` is not supported - indepentent of the fact what columns the `df` stores. You need to user the constructor.
