# IndexedTable to DataFrame

**URL:** <https://discourse.julialang.org/t/indexedtable-to-dataframe/26528>\
**Category:** General Usage\
**Tags:** juliadb\
**Created:** [July 19, 2019, 4:06am UTC](https://discourse.julialang.org/t/indexedtable-to-dataframe/26528 "2019-07-19T04:06:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bernhard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernhard/32/2619_2.png) [@bernhard](https://discourse.julialang.org/u/bernhard)\
**Post date:** [July 19, 2019, 4:06am UTC](https://discourse.julialang.org/t/indexedtable-to-dataframe/26528/1 "2019-07-19T04:06:50Z")

</div>

I am wondering how to convert an IndexedTable to a DataFrame. There are two posts that offer (partial) solutions to this, but I am not sure if that is (still) the best way.

> <https://stackoverflow.com/questions/46844516/how-to-convert-an-indexedtable-to-a-dataframe-in-julia>

> [@Pulling array data from IndexedTables or JuliaDB](https://discourse.julialang.org/t/pulling-array-data-from-indexedtables-or-juliadb/3651):
>
> Typically, to do anything useful with tabular data it has to be converted to a plain-old array, often of floats. And, far worse, usually you have to take the output from doing something to said array back into the data in the form of an additional column. Indeed, I never cease to be amazed at how many obstacles there are to this in sources as diverse as csv’s, SQL and parquet. One thing I really love about DataTables and DataFrames, is that, since they are simple containers of named vectors, …

For now, it is not clear to me when it is preferable to work with JuliaDB/IndexedTable and when it is preferable to work with a DataFrame. I am not sure if there is any guidance on this. As long as it fits in memory I can/should stay with a DataFrame? In my case, I certainly have more options/tools/experience with DataFrames.

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [July 19, 2019, 1:31pm UTC](https://discourse.julialang.org/t/indexedtable-to-dataframe/26528/2 "2019-07-19T13:31:54Z")

</div>

This is actually incredibly simple now thanks to Tables.jl:

```julia
julia> t = table((x=1:5, y=randn(5)))
Table with 5 rows, 2 columns:
x y
────────────
1 1.22615
2 0.688459
3 -0.999314
4 0.279394
5 0.192156

julia> DataFrame(t)
5×2 DataFrame
│ Row │ x │ y │
│ │ Int64 │ Float64 │
├─────┼───────┼───────────┤
│ 1 │ 1 │ 1.22615 │
│ 2 │ 2 │ 0.688459 │
│ 3 │ 3 │ -0.999314 │
│ 4 │ 4 │ 0.279394 │
│ 5 │ 5 │ 0.192156 │

```

Likewise, you can do `table(df)`.

---

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [July 30, 2019, 12:37pm UTC](https://discourse.julialang.org/t/indexedtable-to-dataframe/26528/3 "2019-07-30T12:37:42Z")

</div>

If you are working with a Distributed Table, you can convert it to a DataFrame like so:

```julia
df = DataFrame(collect(my_distributed_table))

```

---

<div class="post-metadata">

**Author:** ![bernhard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernhard/32/2619_2.png) [@bernhard](https://discourse.julialang.org/u/bernhard)\
**Post date:** [August 5, 2019, 8:17am UTC](https://discourse.julialang.org/t/indexedtable-to-dataframe/26528/4 "2019-08-05T08:17:32Z")

</div>

What if I am working with a `DNDSparse`?

I have **omitted** some column names and types in this snippet:

```julia
dta=loadndsparse(fileNamesToBeLoaded,
header_exists=true,
chunks=1
,colparsers=thisTypeDictMod);

typeof(dta)

JuliaDB.DNDSparse{Tuple{Int64},NamedTuple{(:tip,:name3,:number1 ........),Tuple{UInt32,String, ..........}}}

```

I tried these three approaches and all fail

```julia
DataFrame(dta);
DataFrame(table(dta));
DataFrame(collect(dta));

```

```julia
julia> DataFrame(collect(dta));
ERROR: MethodError: no method matching Tables.Schema(::Type{Tuple{Int64,UInt32,String,String,String,Int64,Int64,Int64,Int64,Int64,Int64,Int64,String,Int64,Int64,String,Int64,Int64,String,Int64,Int64,String,String,String,String,String,String,String,Union{Missing, UInt16},Union{Missing, UInt16},String,String}})

DataFrame(dta);
ERROR: ArgumentError: no default `Tables.columns` implementation for type: JuliaDB.DNDSparse{Tuple{Int64},NamedTuple{(:tipNr,.....

```
