Could you post an executable code snippet to reproduce this issue, please?
You can use random input data (instead of a real dataset), which would make debugging easier.
PS: you can post code snippets by wrapping them into three backticks ```