Hi, I am python developer with 5+ years of experience in development.
I went through your code. At present, since there is no access to complete code It's difficult to pinpoint issues.
But to help you and give some heads up, there is issue at line 306.
At line 299 you are calculating max, this will return 'int'; and at line 306 you are using 'iloc' function on int which is incorrect.
I would like to work alongside you, for more details please reach out to me on chat.