此代码按预期正常工作.但是大型数据帧需要花费大量时间.
for i in excel_df['name_of_college_school'] :
for y in mysql_df['college_name'] :
if SequenceMatcher(None, i.lower(), y.lower() ).ratio() > 0.8:
excel_df.loc[excel_df['name_of_college_school'] == i, 'dupmark4'] = y
Run Code Online (Sandbox Code Playgroud)
我猜,我不能在join子句上使用函数来比较这样的值.我该如何对此进行矢量化?
更新:
是否可以以最高分数更新?此循环将覆盖先前的匹配,并且之前的匹配可能比当前匹配更具相关性.
小智 2
您正在寻找的是模糊合并。
a = excel_df.as_matrix()
b = mysql_df.as_matrix()
for i in a:
for j in b:
if SequenceMatcher(None,
i[college_index_a].lower(), y[college_index_b].lower() ).ratio() > 0.8:
i[dupmark_index] = j
Run Code Online (Sandbox Code Playgroud)
永远不要在循环中使用 loc,它会产生巨大的开销。顺便说一句,获取相应列的索引(数字)。用这个 -
df.columns.get_loc("college name")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
133 次 |
| 最近记录: |