# AbstractDataFrame is not iterable, I just want to make a histogram

**URL:** https://discourse.julialang.org/t/abstractdataframe-is-not-iterable-i-just-want-to-make-a-histogram/102391
**Category:** New to Julia
**Tags:** plotting, dataframes, makie
**Created:** [August 2, 2023, 11:53am UTC](https://discourse.julialang.org/t/abstractdataframe-is-not-iterable-i-just-want-to-make-a-histogram/102391 "2023-08-02T11:53:37Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Axze-rgb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/axze-rgb/32/50986_2.png) [@Axze-rgb](https://discourse.julialang.org/u/Axze-rgb)
#### Post date: [August 2, 2023, 11:53am UTC](https://discourse.julialang.org/t/abstractdataframe-is-not-iterable-i-just-want-to-make-a-histogram/102391/1 "2023-08-02T11:53:37Z")

</div>

Hello,

why is it this is not iterable?

Here is the code

> begin  
> CairoMakie.activate!(type = “svg”)  
> fig2 = Figure(pt\_per\_unit = 2)  
> ax2 = Axis(fig[1, 2], xlabel = “MAPQ”)  
> title2 = (“MAPQ of the hifi reads”)  
> hist!(ax2, df2)  
> CairoMakie.save(“MAPG.svg”,fig)  
> fig2  
> end

and my df2 is a single column DataFrame of Int64

I don’t understand why it wouldn’t be iterable. Or why it’s “abstract”?

Thank you

---

<div class="post-metadata">

### Author: ![algunion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/algunion/32/51630_2.png) [@algunion](https://discourse.julialang.org/u/algunion)
#### Post date: [August 2, 2023, 12:45pm UTC](https://discourse.julialang.org/t/abstractdataframe-is-not-iterable-i-just-want-to-make-a-histogram/102391/2 "2023-08-02T12:45:25Z")

</div>

Iterating over a data frame without explicitly stating if you iterate over rows or columns can create confusion. Although I think we can agree that iterating over rows might be more frequent than iterating over columns, I think the decision to require the explicit use of `eachrow` or `eachcol` is a sane one.

You can try this on your end (will output the same error as the one you reported):

```julia
# fails
for x in df2
    println(x)
end

```

However, this works (altogether with `eachcol`):

```julia
# works
for x in eachrow(df2)
    println(x)
end

```

Now, related to your code snippet, it will fail even if you actually use `eachrow` instead of passing the data frame: because iterating in that way will produce `DataFrameRow` elements - and Makie will not do the extra work to detect that in fact you are using a single column and guess your intention of using those values.

To fix this, you’ll need to actually pass the column values:

```julia
hist!(ax2, df2.yourcolumnname)

```

You can use use `df2[:, 1]` if you want to just use the first column without bothering with the name.

Now, related to:

> [@Axze-rgb](#):
>
> Or why it’s “abstract”?

It is not `abstract`, but it has an abstract supertype.

Try to run this on your end: `isa(df2, AbstractDataFrame)`. You’ll see that it evaluates to `true`.

Now, there is a `Base.iterate` method that is implemented to throw a very informative error (pointing towards `eachrow` and `eachcol` usage).

Instead of implementing the method for each concrete type that is a subtype of `AbstractDataFrame`, the method is implemented for the parent abstract type.

I hope this helps.

---

<div class="post-metadata">

### Author: ![Axze-rgb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/axze-rgb/32/50986_2.png) [@Axze-rgb](https://discourse.julialang.org/u/Axze-rgb)
#### Post date: [August 2, 2023, 1:20pm UTC](https://discourse.julialang.org/t/abstractdataframe-is-not-iterable-i-just-want-to-make-a-histogram/102391/3 "2023-08-02T13:20:57Z")

</div>

Thank you and indeed it solved the problem. I was confused because none of the examples in the Makie tutorial have to do that. That being said, I get a white image. The dataframe is 2 million points. It should be able to handle that. I switched to a kernel density, and same, computation is really slow and results in a blank figure.

Therefore, I subsampled my dataframe to 100 (one hundred) and tried to plot an histogram. Bur alas, still just a blank figure. Even if Makie is not the best for millions of points, we agree that 100 points should not be outside of its capabilities, right?

I am really sorry, I feel like a total idiot bringing you questions after questions… Is there a way to contribute and give back to this community? Like a “donate” or something? I would definitely do it at my discretion.

Thanks again

---

<div class="post-metadata">

### Author: ![algunion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/algunion/32/51630_2.png) [@algunion](https://discourse.julialang.org/u/algunion)
#### Post date: [August 2, 2023, 1:53pm UTC](https://discourse.julialang.org/t/abstractdataframe-is-not-iterable-i-just-want-to-make-a-histogram/102391/4 "2023-08-02T13:53:33Z")

</div>

> [@Axze-rgb](#):
>
> Is there a way to contribute and give back to this community? Like a “donate” or something? I would definitely do it at my discretion.

I am not sure about others but at least in my case, this is my way of giving back to the community (e.g., producing more of the things that I found valuable when starting my Julia journey). So my answer above was actually in the same give-back category.

Now, I understand that there are more ways in which one can _give-back_. If you are inclined towards a donation, my feeling is that [supporting the core language development](https://github.com/sponsors/JuliaLang) is a valuable way to spend money. However, I am not knowledgeable enough about the precise ways things work at that level - so maybe somebody with more information can jump in and add more context.

* * *
Regarding your additional questions, I think the best way is to create another topic and provide a minimal working example. That will speed up the time needed to solve your problem and be valuable for others that might encounter similar issues (this will aid the search functionality - both here on discourse and from outside search engines).

---

<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: [August 2, 2023, 11:22pm UTC](https://discourse.julialang.org/t/abstractdataframe-is-not-iterable-i-just-want-to-make-a-histogram/102391/5 "2023-08-02T23:22:40Z")

</div>

@algunion is 100% correct. We require an explicit call to `eachrow` or `eachcol` because different other ecosystems chose one option or the other as a default and users coming to DataFrames.jl were sometimes confused.

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [August 3, 2023, 1:08am UTC](https://discourse.julialang.org/t/abstractdataframe-is-not-iterable-i-just-want-to-make-a-histogram/102391/6 "2023-08-03T01:08:28Z")

</div>

Sorry for low quality post but doing it from iPad and codespaces.  
With GMT.jl it takes half a second to compute the histogram of a million points.

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

---

<div class="post-metadata">

### Author: ![algunion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/algunion/32/51630_2.png) [@algunion](https://discourse.julialang.org/u/algunion)
#### Post date: [August 3, 2023, 2:14am UTC](https://discourse.julialang.org/t/abstractdataframe-is-not-iterable-i-just-want-to-make-a-histogram/102391/7 "2023-08-03T02:14:48Z")

</div>

> [@joa-quim](#):
>
> With GMT.jl it takes half a second to compute the histogram of a million points.

Not sure what is going on there - `CairoMakie`’s `hist!` takes under 0.04 seconds for 1M points and 0.2 for 10M.

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [August 3, 2023, 12:42pm UTC](https://discourse.julialang.org/t/abstractdataframe-is-not-iterable-i-just-want-to-make-a-histogram/102391/8 "2023-08-03T12:42:30Z")

</div>

This brings me a faint recall of something on C histogram in GMT but can’t test it right now.

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [August 3, 2023, 1:01pm UTC](https://discourse.julialang.org/t/abstractdataframe-is-not-iterable-i-just-want-to-make-a-histogram/102391/9 "2023-08-03T13:01:35Z")

</div>

> [@Axze-rgb](#):
>
> Even if Makie is not the best for millions of points, we agree that 100 points should not be outside of its capabilities, right?

A histogram does not actually plot the points you give it, just a couple bars, so you should be able to throw almost an arbitrary number of points at it. For me, 100 million take about 3 seconds to render. A white image suggests something else is going on.

With GLMakie you should be able to handle a couple million points at interactive speeds.
