One way to get this error could be to have the dataset claim a length larger than the list you are indexing.
Best regards
Thomas
PS Enclosing your code in triple backticks ``` will give it code formatting.
PPS Welcome here!