首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >mongodb中的直方图

mongodb中的直方图
EN

Stack Overflow用户
提问于 2020-12-11 19:55:21
回答 1查看 72关注 0票数 0

这段代码有什么问题?

代码语言:javascript
运行
复制
File "<ipython-input-17-728073f2f109>", line 17
    {"$toInt" : 'page_start'}]}}},
                                 ^
SyntaxError: invalid syntax

你知道这意味着什么吗?

代码语言:javascript
运行
复制
import pandas as pd

def length_vs_references(articles):

    res = {"1-5" : 0, "6-10" : 0, "11-15" : 0, "16-20" : 0, "21-25" : 0, "25-30" : 0, ">30" :0}
    n = {"1-5" : 0, "6-10" : 0, "11-15" : 0, "16-20" : 0, "21-25" : 0, "25-30" : 0, ">30" :0}
    
    cursor = articles.aggregate([
        {'$match': {'$and' : [{'references': {'$exists': False}
        }, {'$ne':['$page_end', '']}, {'$ne':['$page_start', '']} ]}},
        {'$project': {'len_refernces': {"$size": '$references'},
                                                'pages': {'$subtract': [{"$toInt": 'page_end'},
                                                                        {"$toInt" : 'page_start'}]}}},
        
            {'$bucket' :{
            '$groupBy': '$pages',
            'boundaries': [ 0, 6, 11, 16, 21, 26, 31, 1000000],
                'default': 'Other',
             'key': {
                 'output': {"average": {"$avg" : '$len_references'}},
            }
                }
            }       
    ])
    return cursor
 

print(length_vs_references(articles))
EN

回答 1

Stack Overflow用户

发布于 2020-12-11 20:33:58

您错过并添加了一些$。布尔值为true/false

应该是这个:

代码语言:javascript
运行
复制
articles.aggregate([
   {
      '$match': {
         'references': { '$exists': false },
         'page_end': { '$ne': '' },
         'page_start': { '$ne': '' }
      }
   },

   {
      '$project': {
         'len_refernces': { "$size": '$references' },
         'pages': {
            '$subtract': [
               { "$toInt": '$page_end' },
               { "$toInt": '$page_start' }
            ]
         }
      }
   },

   {
      '$bucket': {
         'groupBy': '$pages',
         'boundaries': [0, 6, 11, 16, 21, 26, 31, 1000000],
         'default': 'Other',
         'output': {
            "average": { "$avg": '$len_references' }
         },
      }
   }
])
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65250920

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档