这段代码有什么问题?
File "<ipython-input-17-728073f2f109>", line 17
{"$toInt" : 'page_start'}]}}},
^
SyntaxError: invalid syntax你知道这意味着什么吗?
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))发布于 2020-12-11 20:33:58
您错过并添加了一些$。布尔值为true/false。
应该是这个:
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' }
},
}
}
])https://stackoverflow.com/questions/65250920
复制相似问题