0

我在网上关注各种关于 python 重复数据删除的教程,但无论我尝试哪一个,都会遇到这个错误:

ValueError: Records do not line up with data model. The field 'firstname ' is in data_model but not in a record

有人在他们的 github 上遇到了同样的问题:https ://github.com/dedupeio/csvdedupe/issues/55 ,开发人员说训练示例必须具有此错误消息中的任何记录。

我的数据有firstname记录,字段变量也有。

要删除的数据:


{76550: {'id': '76550',
  'title': 'mrs',
  'firstname': 'mary',
  'lastname': 'fakename',
  'email': 'fakemail@yahoo.com',
  'phone': None,
  'mobile': '353870748',
   etc etc etc}

以下是字段:


fields = [
        {'field' : 'firstname ', 'type': 'String','has missing' : True},
        {'field' : 'lastname ', 'type': 'String','has missing' : True},
        {'field' : 'email', 'type': 'String','has missing' : True},
        {'field' : 'address1', 'type': 'String', 'has missing' : True},
        {'field' : 'mobile', 'type': 'String', 'has missing' : True},
        ]

错误是在这里引起的:


# Pass in our model
deduper = dedupe.Dedupe(fields)

# Feed some sample data in ... 1500 records
deduper.sample(df, 1500)

ValueError                                Traceback (most recent call last)
<ipython-input-89-e34caa52a74c> in <module>
      2 
      3 # Feed some sample data in ... 15000 records
----> 4 deduper.sample(df, 1500)

~\Anaconda3\envs\Tensorflow\lib\site-packages\dedupe\api.py in sample(self, data, sample_size, blocked_proportion, original_length)
    789                                a sample of full data
    790         '''
--> 791         self._checkData(data)
    792 
    793         self.active_learner = self.ActiveLearner(self.data_model,

~\Anaconda3\envs\Tensorflow\lib\site-packages\dedupe\api.py in _checkData(self, data)
    802                 'Dictionary of records is empty.')
    803 
--> 804         self.data_model.check(next(iter(viewvalues(data))))
    805 
    806 

~\Anaconda3\envs\Tensorflow\lib\site-packages\dedupe\datamodel.py in check(self, record)
    119                 raise ValueError("Records do not line up with data model. "
    120                                  "The field '%s' is in data_model but not "
--> 121                                  "in a record" % field)
    122 
    123 

ValueError: Records do not line up with data model. The field 'firstname ' is in data_model but not in a record

两者都有firstname

我哪里错了?

我尝试过转置数据框并以各种方式转换为 dict 。我无法让它工作。

4

1 回答 1

1

问题是在你的字段定义中你有一个额外的空间

你要

'firstname'

不是

'firstname '

于 2020-03-05T06:56:36.423 回答