Hi there! Since this is your first post, welcome.
To add on to what @ccoffrin said: I’m not sure what the problem is because I can’t run your code. We might be able to provide more insight if you can provide the (simplified) data, or if you can provide the full error message. This post has some helpful tips on writing a good question: Please read: make it easier to help you