Home > OS >  Checking progress of an ongoing for loop in JupyterLab
Checking progress of an ongoing for loop in JupyterLab

Time:08-14

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)

CodePudding user response:

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")
  • Related