# How can I convert this type of dictionary into a dataframe?

**URL:** <https://discourse.julialang.org/t/how-can-i-convert-this-type-of-dictionary-into-a-dataframe/34321>\
**Category:** General Usage\
**Tags:** first-steps\
**Created:** [February 7, 2020, 7:44pm UTC](https://discourse.julialang.org/t/how-can-i-convert-this-type-of-dictionary-into-a-dataframe/34321 "2020-02-07T19:44:10Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aizzaac](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@Aizzaac](https://discourse.julialang.org/u/Aizzaac)\
**Post date:** [February 7, 2020, 7:44pm UTC](https://discourse.julialang.org/t/how-can-i-convert-this-type-of-dictionary-into-a-dataframe/34321/1 "2020-02-07T19:44:10Z")

</div>

Hi

I have used a Python SDK to extract data from Splunk.  
In the image you can see an example of the output.

![image](https://global.discourse-cdn.com/julialang/original/3X/3/4/34e34fe9af1c737c5b32641c2079c229eacf37c7.png)

I want to send that information to a DataFrame.

Any clues will be helpful.

Thank yoi

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [February 7, 2020, 7:58pm UTC](https://discourse.julialang.org/t/how-can-i-convert-this-type-of-dictionary-into-a-dataframe/34321/2 "2020-02-07T19:58:51Z")

</div>

Assuming that you have those in a vector `Dv`,

```julia
vcat(DataFrame.(Dv)...)

```

would work. You could also convert them to NamedTuples instead of Dicts and then construct the DataFrame.

---

<div class="post-metadata">

**Author:** ![Aizzaac](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@Aizzaac](https://discourse.julialang.org/u/Aizzaac)\
**Post date:** [February 7, 2020, 8:21pm UTC](https://discourse.julialang.org/t/how-can-i-convert-this-type-of-dictionary-into-a-dataframe/34321/3 "2020-02-07T20:21:26Z")

</div>

I am iterating. This is the original code:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/a/9a53717235c8c58035615e122d9d9c094a4e57cd.png)

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [February 7, 2020, 8:27pm UTC](https://discourse.julialang.org/t/how-can-i-convert-this-type-of-dictionary-into-a-dataframe/34321/4 "2020-02-07T20:27:03Z")

</div>

That doesn’t change anything. You can either collect the `Dict`s into a vector during your loop and use my suggestion afterwards, or you can create one-row `DataFrame`s while you iterate (using `df = DataFrame(item)`) and collect them into a single one afterwards (again using `vcat`).

---

<div class="post-metadata">

**Author:** ![Aizzaac](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@Aizzaac](https://discourse.julialang.org/u/Aizzaac)\
**Post date:** [February 7, 2020, 8:38pm UTC](https://discourse.julialang.org/t/how-can-i-convert-this-type-of-dictionary-into-a-dataframe/34321/5 "2020-02-07T20:38:26Z")

</div>

This is the second option `you can create one-row DataFrames while you iterate`:

![image](https://global.discourse-cdn.com/julialang/original/3X/6/b/6bcb2705210b7bff0cc29e15a3a9e470eb5033bb.png)

It seems to be working.

But how can I see the dataframe?

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [February 7, 2020, 8:52pm UTC](https://discourse.julialang.org/t/how-can-i-convert-this-type-of-dictionary-into-a-dataframe/34321/6 "2020-02-07T20:52:28Z")

</div>

That is not going to be doing what you want, you aren’t actually accumulating anything. Try this

```julia
Dv = Vector{Dict}()
for item in reader
    push!(Dv,item)
end
df=vcat(DataFrame.(Dv)...)

```

And, just taking a guess here,

```julia
df=vcat(DataFrame.(reader)...)

```

would probably work (since I see you are just printing with the loop anyway).

---

<div class="post-metadata">

**Author:** ![Aizzaac](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@Aizzaac](https://discourse.julialang.org/u/Aizzaac)\
**Post date:** [February 7, 2020, 9:11pm UTC](https://discourse.julialang.org/t/how-can-i-convert-this-type-of-dictionary-into-a-dataframe/34321/7 "2020-02-07T21:11:42Z")

</div>

> [@tbeason](#):
>
> df=vcat(DataFrame.(reader)…)

This is what I get

![image](https://global.discourse-cdn.com/julialang/original/3X/8/2/824f43189c0586b9d14560537f8a41c810ed0486.png)

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [February 7, 2020, 9:13pm UTC](https://discourse.julialang.org/t/how-can-i-convert-this-type-of-dictionary-into-a-dataframe/34321/8 "2020-02-07T21:13:14Z")

</div>

You need to `using DataFrames`

---

<div class="post-metadata">

**Author:** ![Aizzaac](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@Aizzaac](https://discourse.julialang.org/u/Aizzaac)\
**Post date:** [February 7, 2020, 9:15pm UTC](https://discourse.julialang.org/t/how-can-i-convert-this-type-of-dictionary-into-a-dataframe/34321/9 "2020-02-07T21:15:00Z")

</div>

I think is the same problem I have with Python:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/b/db9c9146e4051d4e51eed164cbc3cb4dc03f68bf.png)

JULIA  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/7/a7a09bb78545c202faa5fd5ee68323530d399699.png)

---

<div class="post-metadata">

**Author:** ![Aizzaac](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@Aizzaac](https://discourse.julialang.org/u/Aizzaac)\
**Post date:** [February 7, 2020, 10:14pm UTC](https://discourse.julialang.org/t/how-can-i-convert-this-type-of-dictionary-into-a-dataframe/34321/10 "2020-02-07T22:14:14Z")

</div>

Okey. It has worked in Python.  
Now I will check Julia.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/5/45045b452fd0765cd1699a9f297e35ca6f92ff3d.png)

---

<div class="post-metadata">

**Author:** ![Aizzaac](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@Aizzaac](https://discourse.julialang.org/u/Aizzaac)\
**Post date:** [February 9, 2020, 3:51pm UTC](https://discourse.julialang.org/t/how-can-i-convert-this-type-of-dictionary-into-a-dataframe/34321/11 "2020-02-09T15:51:00Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/b/f/bf90f23a2611cb5d6563817a2d28c9026ae56ab6.png)

The iteration never accumulates anything.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [February 9, 2020, 4:28pm UTC](https://discourse.julialang.org/t/how-can-i-convert-this-type-of-dictionary-into-a-dataframe/34321/12 "2020-02-09T16:28:01Z")

</div>

Can you give a MWE with code written in backticks, as follows, rather than screenshots?

````julia
```
Your code here
```

````

It seems like `reader` might be empty. Having a MWE will help determine that that’s the problem.

---

<div class="post-metadata">

**Author:** ![Aizzaac](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@Aizzaac](https://discourse.julialang.org/u/Aizzaac)\
**Post date:** [February 9, 2020, 7:13pm UTC](https://discourse.julialang.org/t/how-can-i-convert-this-type-of-dictionary-into-a-dataframe/34321/13 "2020-02-09T19:13:08Z")

</div>

This is the code. It is now working!!!  
I used “collect”.

```
results=pyimport("splunklib.results")

kwargs_oneshot = (earliest_time= "2019-09-07T12:00:00.000-07:00",
              latest_time= "2019-09-09T12:00:00.000-07:00",
              count=0)

searchquery_oneshot = "search index=iis | lookup geo_BST_ONT longitude as sLongitude, latitude as sLatitude | stats count by featureId | geom geo_BST_ONT allFeatures=True | head 2" 

oneshotsearch_results = service.jobs.oneshot(searchquery_oneshot; kwargs_oneshot...)

# Get the results
reader = results.ResultsReader(oneshotsearch_results)

# collect them into an array
Dv = collect(reader)

using DataFrames
df=vcat(DataFrame.(Dv)...)

```
