BoundsError: attempt to access "attempt to access a data frame with 6 columns at index 14"

Hello everyone,

I am a little confused and I need your help because I am not able to understand my error.
I wrote this two functions but for both of them I have the following error: BoundsError: attempt to access “attempt to access a data frame with 6 columns at index 14”.
My dataframe is a scv file

I would be really grateful if someone could help me to understand this error and what to do about it.
Thank you!

The size function returns a tuple containing the number of dimensions of each index of an array, or, in this case, a DataFrame. Since you seem to be attempting to iterate over the columns of the dataframe, what you are looking for is size(df,2) which gives the number of dimensions of the second index, in this case the number of columns. Note that this will return an integer, so what you want is 1:size(df,2) which gives all integers in that range (inclusive).

Lastly, I recommend using function signatures like

function normalize(df::AbstractDataFrame, startcols=2)


This would allow your functions to operate on any AbstractDataFrame, not just DataFrame (which is a concrete sub-type of AbstractDataFrame). Probably not important here, but it’s good to get in the habit of writing generic code, since the ease of writing generic code is one of the best aspects of Julia. In general, you shouldn’t necessarily feel compelled to include types in function signatures. There is no performance penalty to omitting them.

Thank you very much for your fast and very complete reply. I’ll try this immediately!
Thank you again.

Yes, to second what was mentioned above, you don’t need type signatures to necessarily improve performance although if it helps you understand the types of inputs better (say, you’re coming back to the same code after a year), you can include type signatures for clarity.