在使用此代码时,我得到了此错误,该代码使用spacy搜索文本文件中的特定术语,然后将这些项添加到熊猫数据文件中。
for ind,match in enumerate(matches):
for sent in sents:
if matches[ind][1] < sent.end:
typematches = findmatch(sent,['Greenfield','greenfield', 'brownfield','Brownfield', 'de-bottlenecking', 'De-bottlenecking'],'Type')
valuematches = findmatch(sent,['Crore', 'Cr','crore', 'cr'],'Value')
datematches = findmatch(sent,['2020', '2021','2022', '2023','2024', '2025', 'FY21', 'FY22', 'FY23', 'FY24', 'FY25','FY26'],'Date')
for match_id , start, end in itertools.zip_longest(typematches, valuematches, datematches):
string_id = nlp.vocab.strings[match_id]
span = doc[start:end]
capextype = span.text
allcapex.loc[len(allcapex.index)] = [capextype,'a','a','a','a']
break运行此代码后,我将得到以下错误
line 126, in spacy.strings.StringStore.__getitem__ TypeError: '<' not supported between instances of 'tuple' and 'int'发布于 2022-02-15 06:05:49
zip_longest不像你想的那样做。
我假设您希望将匹配连接起来,这意味着您应该使用itertools.chain,而不是zip_longest。
现在,调用match_id、start和end的变量实际上是每个匹配项的一个元组,这很奇怪,不会给出有意义的结果。
https://stackoverflow.com/questions/71114647
复制相似问题