When executing a Python cell, the following steps are performed:
Imported packages are downloaded and installed (if needed)
Upstream cells are loaded into Pandas DataFrames
Your Python code is executed
The result of your Python code is converted into a table to be displayed
Most of these steps should be quite quick. If a cell is slow, first try profiling your code to see if there are any particularly slow parts. For example, you could use the cProfile
package to define a profile
function:
import cProfile, pstats, io
from pstats import SortKey
def profile(func):
pr = cProfile.Profile()
pr.enable()
func()
pr.disable()
s = io.StringIO()
ps = pstats.Stats(pr, stream=s).sort_stats(SortKey.CUMULATIVE)
ps.print_stats()
return s.getvalue()
which you would then use as follows:
In this (trivial) example, it is clear that all of the time is spent in the regular expression constructor method __init__
.
If you do not identify any long-running parts of your code, and are concerned that your Python cells are slow for other reasons, please contact Count support.
--
For more information on Python in Count, check out our docs.