TypeError: ‘RDD’ object does not support indexing [on hold]

I am working on the optimization of an algorithm which is implemented in python and Now I want to optimize it using Pyspark. I have checked my code and works fine however there is an error in the last line stating @TypeError: ‘RDD’ object does not support indexing”. I need help to solve the error or suggest an alternative to do it. Thanks. Snapshots of code are attached.

Code showing value for variables Error