Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.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
Python 映射时间戳上的Reduce_Python_Mongodb - Fatal编程技术网

Python 映射时间戳上的Reduce

Python 映射时间戳上的Reduce,python,mongodb,Python,Mongodb,Mongodb数据库: {"thread": "abc", "message": "hjhjh", "Date": (2010,4,5,0,0,0)} {"thread": "abc", "message": "hjhjh", "Date": (2009,3,5,0,0,0)} {"thread": "efg", "message": "hjhjh", "Date": (2010,3,7,0,0,0)} {"thread": "efg", "message": "hjhjh", "Date

Mongodb数据库:

{"thread": "abc", "message": "hjhjh", "Date": (2010,4,5,0,0,0)}
{"thread": "abc", "message": "hjhjh",  "Date": (2009,3,5,0,0,0)}
{"thread": "efg", "message": "hjhjh",  "Date": (2010,3,7,0,0,0)}
{"thread": "efg", "message": "hjhjh",  "Date": (2011,4,5,0,0,0)}
我如何映射或聚合上述数据以生成以下输出:

{"thread": "abc", "messages_per_month": 5}
{"thread": "efg", "messages_per_month": 4}

我正在尝试编写一些代码,但很难对未排序的日期进行平均。是否有任何内置函数可以按时间平均执行此操作?

您可以按数字所述的日期执行min/max,只需为消息添加一个计数器即可。结果将是一个包含消息数和最小/最大日期的线程列表。从日期开始,您可以计算月数,然后使用月数计算邮件数的平均值