How to calculate a stochastic oscillator in python?

How can I calculate the stochastic oscillator? I tried to use a formula from wikipedia, but I got practical random data. I found this script, but I don’t quite understand how it works, and it also seems to give out incorrect data.

You can use the library - ‘ta-lib’ to calculate it. TAlib.Indicators.Stochastic — TAlib v0.3.6