python code for derivate calculations