I used jupyter notebook here.
This code is from a youtube video. It was working in the youtuber's computer but mine raise a Stopiteration error
Here I am trying to get all the titles(questions from the csv) that are questions related to 'Go' language
import pandas as pd
df = pd.read_csv("Questions.csv", encoding = "ISO-8859-1", usecols = ["Title", "Id"])
titles = [_ for _ in df.loc[lambda d: d['Title'].str.lower().str.contains(" go "," golang ")]['Title']]
#new cell
import spacy
nlp = spacy.load("en_core_web_sm" , disable= ["ner"])
#new cell
def has_golang(text):
doc = nlp(text)
for t in doc:
if t.lower_ in [' go ', 'golang']:
if t.pos_ != 'VERB':
if t.dep_ == 'pobj':
return True
return False
g = (title for title in titles if has_golang(title))
[next(g) for i in range(10)]
#This is the error
StopIteration Traceback (most recent call last)
<ipython-input-56-862339d10dde> in <module>
9
10 g = (title for title in titles if has_golang(title))
---> 11 [next(g) for i in range(10)]
<ipython-input-56-862339d10dde> in <listcomp>(.0)
9
10 g = (title for title in titles if has_golang(title))
---> 11 [next(g) for i in range(10)]
StopIteration:
As far as I have done the research I think it might be a bug
All I want to do is get those titles that satisfy the 3 'if' conditions