gpt4 book ai didi

python - Pymongo-值错误 : NaTType does not support utcoffset when using insert_many

转载 作者:太空宇宙 更新时间:2023-11-03 15:39:58 44 4
gpt4 key购买 nike

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

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

2016-09-22 00:00:00

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

2016-09-27 09:03:08.988

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

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

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

任何帮助表示赞赏。

最佳答案

将其替换为 pandas 可以解释的 None 值

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

关于python - Pymongo-值错误 : NaTType does not support utcoffset when using insert_many,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42228292/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com