Checking progress of an ongoing for loop in JupyterLab

Question:

I have been running a for loop for 4 days now. I understand that there are better ways to do it, but I needed to run it just once. Is there a way to check the progress without interrupting the loop? I’m terrified to loose all of my progress.
This is my code

#scoring the sentences
for i in range(len(df.hope)):
  for word in words:
    df.hope[i] += df.text[i].count(word)
  for word_f in words_f:
    df.fear[i] += df.text[i].count(word_f)
Asked By: user18694315

||

Answers:

Given the information from your comment, here is the most efficient way of computing it in Python (as far as I know).

df['hope'] = df.text.str.count("(" + "|".join(words) + ")")
df['fear'] = df.text.str.count("(" + "|".join(words_f) + ")")

Hopefully this will terminate in a reasonable amount of time!

Edit:

I forgot to add that you have to cast the text column to the "string" datatype. Before doing the above, cast the text column using

df.text = df.text.astype("string")
Answered By: Marcel
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.