Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb mapreduce可查找多个最大值_Mongodb_Pandas_Pymongo - Fatal编程技术网

Mongodb mapreduce可查找多个最大值

Mongodb mapreduce可查找多个最大值,mongodb,pandas,pymongo,Mongodb,Pandas,Pymongo,试图了解如何使用map_reduce执行此操作。目前,我做了一个发现,将整个集合拉入一个大熊猫数据框。df包含如下内容: project ep seq shot layers totalframes showA sh18 17120 10 cnt_chr_set 128 showA sh18 17040 70 shd_chr_set 288 showA sh1

试图了解如何使用map_reduce执行此操作。目前,我做了一个发现,将整个集合拉入一个大熊猫数据框。df包含如下内容:

project     ep     seq     shot     layers          totalframes
showA     sh18     17120     10     cnt_chr_set     128
showA     sh18     17040     70     shd_chr_set     288
showA     sh18        80    460     chr_rim         131
showA     sh18     17120     20     chr_vol_lgt     120
showA     sh18     17120     10     set_all         128
showA     sh18     17120     20     cnt_chr_set     120
showA     sh18     17120     20     cnt_chr_set     130
showA     sh18     17120     20     cnt_chr_set       3
showA     sh18     17120     20     cnt_chr_set       1
showA     sh18     17120     10     set_all_ani     128
showA     sh18     17120     20     set_all_ani     120
showA     sh18     17040     70     set_all         288
showA     sh18     17120     10     shd_chr_set     128
showA     sh18     17120     20     shd_chr_set     120
showA     sh18     18150     20     chr_ben_steam     3
showA     sh18     18150     20     chr_whi_steam     3
showA     sh18     18150     20     chr_bil_steam     3
showA     sh18     17040     70     chr_sal_steam   288
{$group : {"_id" : "$layers", "max_totalframes" : {"$max" : "$totalframes"}}}
我实际上需要做的是,找到每一层的最大总帧数。生成的数据帧应仅包含快照的每个层中的一个。例如:

showA     sh18     17120     20     chr_vol_lgt     120
showA     sh18     17120     20     cnt_chr_set     130
showA     sh18     17120     20     set_all_ani     120
事实上,我一直试图通过熊猫来达到这一点,但似乎有太多的数据需要处理。仅将我需要的信息从mongodb拉入数据框似乎是正确的方法,但我不知道从哪里开始使用map_reduce


指针很受欢迎。

当查看您的数据时,您会发现它在SQL中是一个简单的“分组依据”,map reduce可能是不必要的

我在考虑一个聚合查询,大致如下:

project     ep     seq     shot     layers          totalframes
showA     sh18     17120     10     cnt_chr_set     128
showA     sh18     17040     70     shd_chr_set     288
showA     sh18        80    460     chr_rim         131
showA     sh18     17120     20     chr_vol_lgt     120
showA     sh18     17120     10     set_all         128
showA     sh18     17120     20     cnt_chr_set     120
showA     sh18     17120     20     cnt_chr_set     130
showA     sh18     17120     20     cnt_chr_set       3
showA     sh18     17120     20     cnt_chr_set       1
showA     sh18     17120     10     set_all_ani     128
showA     sh18     17120     20     set_all_ani     120
showA     sh18     17040     70     set_all         288
showA     sh18     17120     10     shd_chr_set     128
showA     sh18     17120     20     shd_chr_set     120
showA     sh18     18150     20     chr_ben_steam     3
showA     sh18     18150     20     chr_whi_steam     3
showA     sh18     18150     20     chr_bil_steam     3
showA     sh18     17040     70     chr_sal_steam   288
{$group : {"_id" : "$layers", "max_totalframes" : {"$max" : "$totalframes"}}}

这将返回每个层项目的最高totalframes。如果我正确理解了您的问题,这就是您要寻找的

MapReduce在这里是不必要的,很可能,只需使用聚合框架:

{ "$group" : { "_id" : { "l": "$layers",
                         "s": "$shots"
                       }, 
               "maxframes" : {"$max" : "$totalframes"}
} }

不确定您是否关心其他字段,如果是,您可以将它们添加到“\u id”分组中。如果有必要的话,您可以使用
$project
在另一个阶段重命名字段。

这会不会对层进行分组,而忽略快照?我有有限的图层名称,但有数千个不同的镜头名称。需要找到每一层每一次拍摄的最大值。你说得对。我认为您需要使用$sort by layers:1、totalframes:-1和$first的组合进行聚合。如果明天我有时间的话,我可以准备一份