# BoundsError with Julia DataFrame

**URL:** <https://discourse.julialang.org/t/boundserror-with-julia-dataframe/27624>\
**Category:** General Usage\
**Tags:** dataframes\
**Created:** [August 16, 2019, 6:03pm UTC](https://discourse.julialang.org/t/boundserror-with-julia-dataframe/27624 "2019-08-16T18:03:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaketothepast](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jaketothepast/32/207193_2.png) [@jaketothepast](https://discourse.julialang.org/u/jaketothepast)\
**Post date:** [August 16, 2019, 6:03pm UTC](https://discourse.julialang.org/t/boundserror-with-julia-dataframe/27624/1 "2019-08-16T18:03:01Z")

</div>

Hello everybody,

I am working on an AI experiment involving generating candidate solutions to a problem. My candidates are in the form of smaller dataframes derived from the larger dataset dataframe. The error I’m facing is this:

```julia
ERROR: BoundsError: attempt to access "attempt to access a data frame with 475 rows at index [0, 202, 402, 259]"
Stacktrace:
 [1] getindex(::DataFrames.DataFrame, ::Array{Int64,1}, ::Colon) at /home/jake/.julia/packages/DataFrames/Iyo5L/src/dataframe/dataframe.jl:387
 [2] randomCandidate(::Int64) at /home/jake/Projects/gp-experiment/Experiment.jl:51
 [3] mutate at /home/jake/Projects/gp-experiment/Experiment.jl:28 [inlined]
 [4] main() at /home/jake/Projects/gp-experiment/Experiment.jl:84
 [5] top-level scope at none:0

```

And this is the abridged version of my code.

```julia
function mutate(parent)
    randomCandidate(4)
end

function randomCandidate(n::Integer)
    # Select n random rows from the dataset.
    rows = [randRow() for i = 1:n]
    df[rows, :]
end

function generateInitialPopulation(lambda::Integer, candidateSize::Integer)
    [randomCandidate(candidateSize) for i = 1:lambda]
end

function main()
    # Local variables omitted
    lambda = 4
    mu = 1
    
    while generationNum != GENLIMIT || (best != nothing && fitness(best) != 0)
        # Population fitness evaluation omitted.
        for p in parents
            for i = 1:(lambda/mu)
                push!(pop, mutate(p))
            end
        end

        println("Generation $generationNum, best $best, fitness $bestFitness")
        generationNum += 1
    end

end

```

Apologies for the awful formatting, randomCandidate works in generateInitialPopulation, but when I try to call it as part of mutate, I get the BoundsError, seemingly nothing has changed, other then where I am calling it from, anyone have any idea what might be happening?

---

<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:** [August 16, 2019, 6:09pm UTC](https://discourse.julialang.org/t/boundserror-with-julia-dataframe/27624/2 "2019-08-16T18:09:46Z")

</div>

Indexing in Julia is 1-based by default. It looks like `randRow()` (not provided?) is outputting `0`’s. The valid integer range for that dataframe is [1, 475].

---

<div class="post-metadata">

**Author:** ![jaketothepast](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jaketothepast/32/207193_2.png) [@jaketothepast](https://discourse.julialang.org/u/jaketothepast)\
**Post date:** [August 16, 2019, 6:12pm UTC](https://discourse.julialang.org/t/boundserror-with-julia-dataframe/27624/3 "2019-08-16T18:12:47Z")

</div>

That was it, thank you so much
