擅长:python、mysql、java
<p>更新:此代码遍历列表中的所有单词,并将它们与“Notes”列进行比较。如果有一个单词在“列表”和“注释”中,这个单词将写在新的“输出”列中。您必须使用正则表达式来获得所需的结果。注:
由于“列表”中的单词可能看起来完全不同,但与“列”中的单词具有相同的含义(缩写、拼写、错误、区分大小写),因此很难获得所有不同的情况。因此,也许用“纸袋法”来解决这个问题是有用的。。。你知道吗</p>
<pre><code>#Create a new list
newlist=[]
#Split the sentences of the "Notes" column
[newlist.append(data.loc[i,"Notes"].split(" ")) for i in range(len(data["Notes"]))]
#Create the new column "output" and default the values to be the same as in the column "Notes"
data["output"]=data["Notes"]
#Run through all words
for i in range(len(list)):
for j in range(len(newlist)):
for element in range(len(newlist[j])):
if re.search(newlist[j][element],list[i]):
data.loc[j,"output"]= "' '{0}".format(newlist[j][element])
</code></pre>
<p>如果有一个更矢量化的方法,我将非常感谢评论</p>