Pymongo-ValueError:使用insert_many时,NaTType不支持utcoffset [英] Pymongo - ValueError: NaTType does not support utcoffset when using insert_many

查看:148
本文介绍了Pymongo-ValueError:使用insert_many时,NaTType不支持utcoffset的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文档从一个数据库增量复制到另一个数据库.

I am trying to incrementally copy documents from one database to another.

某些字段包含以下格式的日期时间值:

Some fields contain date time values in the following format:

2016-09-22 00:00:00

而其他人则采用这种格式:

while others are in this format:

2016-09-27 09:03:08.988

我像这样提取并插入文档:

I extract and insert the documents like so:

pd.DataFrame(list(db_prod.db_name.collction_name.find({'_updated_at': {'$gt': last_added_timestamp}}).sort('_updated_at', 1)))
add = (df.to_dict('records'))

try:
    db_incremental.other_db.collection_name.insert_many(add)
except BulkWriteError as bwe:
    print(bwe.details)

这是错误:

  File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py", line 684, in insert_many
    blk.execute(self.write_concern.document)
  File "/usr/local/lib/python2.7/dist-packages/pymongo/bulk.py", line 470, in execute
    return self.execute_command(sock_info, generator, write_concern)
  File "/usr/local/lib/python2.7/dist-packages/pymongo/bulk.py", line 302, in execute_command
    run.ops, True, self.collection.codec_options, bwc)
  File "pandas/tslib.pyx", line 663, in pandas.tslib._make_error_func.f (pandas/tslib.c:14736)
ValueError: NaTType does not support utcoffset

我实际上不需要修改时间戳,只需按原样插入即可.

I dont actually need to modify the timestamps, just insert them as they are.

任何帮助表示赞赏.

推荐答案

用None值替换它,pandas可以解释该值

Replace it with None values which can be interpreted by pandas

df[['_updated_at']] = df[['_updated_at']].astype(object).where(df[['_updated_at']].notnull(), None)

这篇关于Pymongo-ValueError:使用insert_many时,NaTType不支持utcoffset的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆