# Is there an equivalent of eachindex() for DataFrames?

**URL:** <https://discourse.julialang.org/t/is-there-an-equivalent-of-eachindex-for-dataframes/88945>\
**Category:** General Usage\
**Tags:** question, dataframes, type-stability\
**Created:** [October 19, 2022, 7:17am UTC](https://discourse.julialang.org/t/is-there-an-equivalent-of-eachindex-for-dataframes/88945 "2022-10-19T07:17:21Z")\
**Posts on this page:** 1\
**Showing post:** 6

<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:** [October 20, 2022, 7:05am UTC](https://discourse.julialang.org/t/is-there-an-equivalent-of-eachindex-for-dataframes/88945/6 "2022-10-20T07:05:34Z")

</div>

To have high performance you need to use function barrier. Here is a most basic example:

```julia
function_barrier(vec) = ... your code iterating elements of a vector
map(function_barrier, eachcol(df))

```

The point is that in order to be efficient you must pass a column to a separate function. Then inside this function all will be fast.

The reason is that `DataFrame` object is not type stable, so for example even:

```julia
for col in eachcol(df)
    for v in col
        ... your code
    end
end

```

will be slow, because Julia does not know the element type of `col` at compilation time.

---

_[View the full topic](https://discourse.julialang.org/t/is-there-an-equivalent-of-eachindex-for-dataframes/88945)._
