找不到匹配的 csv 文件 KeyError 消息标签

Matching csv files KeyError message label is not found

提问人:newt_coding 提问时间:5/22/2023 最后编辑:Er...newt_coding 更新时间:5/23/2023 访问量:63

问:

我正在使用 python 记录链接,我正在尝试通过公司名称和状态的模糊匹配来合并两个 csv 文件。

运行代码时,我收到一条关于找不到标签的 KeyError 消息,我不明白我需要做什么才能运行代码。

代码如下

import pandas as pd 
import recordlinkage

reference_usa = pd.read_csv('all_reference_usa.csv', index_col='id')
oc_sample = pd.read_csv('oc_sample.csv', index_col='company_number', low_memory=False)

indexer = recordlinkage.Index()
indexer.sortedneighbourhood(left_on='state', right_on='state')
candidates = indexer.index(reference_usa, oc_sample)
print(len(candidates))

compare = recordlinkage.Compare()
compare.string('companyname',
            'name',
            threshold=0.95)
features = compare.compute(candidates, reference_usa,
                        oc_sample)

这是错误消息

File "/Users/Desktop/python/example.py", line 16, in <module>
    features = compare.compute(candidates, reference_usa,
  File "/Users//anaconda3/lib/python3.10/site-packages/recordlinkage/base.py", line 862, in compute
    results = self._compute(pairs, x, x_link)
  File "/Users//anaconda3/lib/python3.10/site-packages/recordlinkage/base.py", line 686, in _compute
    sublabels_left = self._get_labels_left(validate=x)
  File "/Users/anaconda3/lib/python3.10/site-packages/recordlinkage/base.py", line 652, in _get_labels_left
    raise KeyError(error_msg)
KeyError: 'label is not found in the dataframe' ```

merge 模糊 记录链接 python-dedupe

评论


答: 暂无答案