所以我有一个大数据集,其中一列包含从freetext收集的值(因此有些单词拼写错误或拼写类似)。例如:
Diagnosis
----------
headache
headache
headche
UTI
cough
cough
cough
UTIs
UTI
coughs
UTI
...
我正在寻找通过这些数据和“组合”东西的方法。在大多数情况下,大多数条目的拼写都是正确的(例如,“cough”)。例如,我所寻找的是将“coughs”映射为“cough”,因为它的Levenschtein距离很小,“cough”比“coughs”发生的次数更多。在执行此操作时,上述列将映射到:
Diagnosis
----------
headache
headache
headache
UTI
cough
cough
cough
UTI
UTI
cough
UTI
...
所以现在只有三个唯一的值。另外,需要注意的是,我有数千行拼写错误和额外字符,因此手工映射在这里不是一个真正的选项。我已经使用fuzzy-wuzzy包查看了score_排序,但是它花费的时间太长,似乎对我的特定问题不起作用
任何指导都将不胜感激
我们需要这些图书馆:
假设
Diagnosis
是您的列系列:让我们进行一些字符串匹配:
以下是
matches
数据帧:现在,让我们删除不匹配的行。我用了80分。您可以使用您的首选分数:
现在我们有了匹配项,我们需要连接相似的名称。在您的示例中,每件作品中只有一种类型的打字错误。然而,可能还有更多。所以我们需要向图论寻求帮助:
现在我们有了一个包含相似节点集群的图。我们需要将其转换为字典以替换原始数据:
以下是
names_dict
:这种方法的缺点是您无法确定正确的拼写值。但是,您可以稍后手动修复此问题
现在让我们替换原来的系列:
瞧
最后,您可以做的是构建自己的正确字典来纠正统一值:
结果:
相关问题 更多 >
编程相关推荐