This video should provide more information on how TabPy works in Tableau. TabPy can run on every row, but you can also run the computation across the whole table by changing the table calculation to address all values instead of partitioning: Data science applications with TabPy/R - YouTube. Doing this will allow you to return all values from the operation as a single list.
In your code, it's usually best to read in the data from Tableau, though you can import external data in Python. Each column is brought in from Tableau as a Python list, and it's pretty easy to then construct a dataframe and do table operations on it. The result you return to Tableau must either be a constant or a list.