第25行出现语法问题。有人能帮我找出错误吗?我不确定问题是不是在这行之前的代码中。
文件SyntaxError:无效语法,第25行
} #25
^带有语法的行用#25突出显示。提前感谢您:)
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',
{
'output' : {"average": {"$avg" : '$len_references'}},
}
} #25
}
])
return cursor
print(length_vs_references(articles))发布于 2020-12-11 06:14:34
'default': 'Other',
{
'output' : {"average": {"$avg" : '$len_references'}},
}这就是问题所在。您有一个没有关键字名称的子字典。
为了更简单地说明这个问题,这里有一个等效的字典:
mydict = {
'some_key': 5,
'other_key': 10,
'yet_another_key': 100,
3,
'final_key': 1000
}3是一个错误,因为它只是一个没有键名的值。您的代码有一个子字典,而不是一个整数,但这是相同类型的错误。
https://stackoverflow.com/questions/65242853
复制相似问题