我有一个巨大的数据框,有3个记录,有一列叫做description。我也有可能的子串集约5公里
我想得到描述中包含任何子字符串的行。你知道吗
我使用了以下循环
for i in range(0,len(searchstring)):
ss=searchsting[i]
for k in range(0,len(df)):
desc=df['description'].iloc[k].lower()
if (bool(re.search(ss,desc))):
trans.append(df.iloc[k])
问题是搜索5k乘以3M的循环花费了太多的时间。你知道吗
有没有更好的方法来搜索子字符串?你知道吗
如果使用pandas
isin()
函数,速度应该更快示例:
返回索引列表:
我找到了另一种方法。我已经为3M数据集的description列创建了一个单词字典,通过拆分每个单词。(我已将描述中的数字替换为零,并用于生成字典)
现在,在搜索描述时,必须对搜索字符串应用相同的标记化,并使用字典获取特定单词索引的交集,并且只搜索那些字段。这大大减少了我运行程序的总时间。你知道吗
相关问题 更多 >
编程相关推荐