Python重复数据消除包错误:“记录与数据模型不一致”。但一切看起来都很好

2024-04-23 06:45:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我在网上学习了各种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记录,fields变量也有

要删除重复数据的数据:


{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。我不能让它工作


Tags: 数据sampleinselftruefielddatastring