说我有一个单词列表:
listOfWords = ['Apple','Orange','Banana','Potato']
我的数据框如下所示:
In:
ColumnA:
['Apple','Turnip','Banana','Potato']
['Apple','Orange','Banana','Potato']
['Apple','Orange','Pastry','Potato']
['Melon','Orange','Banana','Potato']
['Apple','Orange','Banana','Sandwich']
我当前正在运行以下代码来检索所需的输出
for index, row in df.iterrows():
for word in df['Column']:
if word not in listOfWords:
word.replace(word,"")
Out:
ColumnA:
['Apple','Banana','Potato']
['Apple','Orange','Banana','Potato']
['Apple','Orange','Potato']
['Orange','Banana','Potato']
['Apple','Orange','Banana']
我目前正在12,000条记录和长度为12,000的列表上运行此文件。它已经运行了好几个小时没有错误,但是我不确定这是否是最有效的方法。