【发布时间】:2016-08-20 17:19:36
【问题描述】:
是否有任何方便的方法可以将 mongodb 组操作的结果加载到 pandas DataFrame 中?
这是 mongo 查询的分组类型:
'$group': {
'_id': {'country': '$country', 'oem':'$oem'},
'count': {'$sum': 1}
}
返回的字典列表如下所示:
[
...
{ "_id" : { "country" : "US", "oem" : "mmm" }, "count" : 595 },
...
]
我希望将其加载到 DataFrame 中,以便 country 和 oem 自动成为索引。除了重新映射结果之外,Pandas API 中是否有任何东西可以处理这个问题?或者我可以以某种方式重新编写 mongo 查询,以便它返回一个对 pandas API 更友好的结构?
【问题讨论】:
-
你的预期输出是什么?
-
具有三列的数据框:
country、oem和count(可选地由country和oem索引)
标签: python mongodb pandas dataframe