我有一个高嵌套字典,其中包含以下数据帧:
{HEAD:
{NameOne:
{TAG : VALUE}
}
{NameTwo : DataFrame}
{NameThree : DataFrame}
}
我想通过PyMongo发送给MongoDB
client = MongoClient('mylink')
db = client['DB_NAME']
collection = db['COLLECTION_NAME']
file = {...}
collection.insert_one(file)
但我有一个错误:
bson.errors.InvalidDocument: cannot encode object: he show my Dataframe here of type:
Pymongo需要能够将字典的每个元素转换为可以存储为BSON文档的内容。如果您尝试插入一些无法转换的内容(例如熊猫数据帧),您将看到
InvalidDocument
异常在将文档存储到MongoDB之前,您必须将每个嵌入的数据帧转换为pymongo可以编码的内容
你可以从^{} 开始
相关问题 更多 >
编程相关推荐