thanks for your comment.
I am not sure I completely follow you on your advice, the error comes at the first element from the for loop, as if there was no first element.
Strangely, when I tried to run it outside of my train function it was working.
I checked everything again but the dataset is not altered in the process so I dont understand why I get this error inside the function