我的问题有点棘手。我已经将我的庞大数据文件分解成块,并多次对每个块应用模糊模糊的代码。之后,我将结果整理到一个文件中。我想知道是否可以应用某种循环来重用代码而不是为每个变量编写它。下面是示例。
df = pd.read_csv('dec 10.csv')
df1 = df.iloc[0:20000]
df2 = df.iloc[20000:40000]
df3 = df.iloc[40000:60000]
match1 = df1['Customer Name'].map(lambda x: difflib.get_close_matches(x, df1['Customer Name'].values, n=2, cutoff=0.8)).apply(pd.Series).dropna(axis=0)
match2 = df2['Customer Name'].map(lambda x: difflib.get_close_matches(x, df2['Customer Name'].values, n=2, cutoff=0.8)).apply(pd.Series).dropna(axis=0)
match3 = df3['Customer Name'].map(lambda x: difflib.get_close_matches(x, df3['Customer Name'].values, n=2, cutoff=0.8)).apply(pd.Series).dropna(axis=0)
a = match1.append(match2, ignore_index =True)
b = a.append(match3, ignore_index =True)
我正在寻找一种优化的方法来编写一次匹配代码,而不是为每个数据块编写它,然后稍后对其进行整理。
米琪卡哇伊
相关分类