gpt4 book ai didi

python - alchemyapi-recipes-twitter - 无法正常工作

转载 作者:行者123 更新时间:2023-11-30 23:12:43 26 4
gpt4 key购买 nike

代码的 github 链接如下:

https://github.com/AlchemyAPI/alchemyapi-recipes-twitter

运行recipe.py时出现以下错误:

Traceback (most recent call last):
File "recipe.py", line 340, in <module>
main(sys.argv[1], int(sys.argv[2]))
File "recipe.py", line 43, in main
print_results()
File "recipe.py", line 303, in print_results
avg_pos_score = mean_results['result'][2]['avgScore']
TypeError: 'CommandCursor' object has no attribute '__getitem__'

我使用的是Python版本2.7.6请帮我解决这个问题。

最佳答案

是的,我终于得到了正确的输出。感谢 Games Brainiac 帮助我解决了这个问题。

    mean_results = list(tweets.aggregate([{"$group" : {"_id": "$sentiment",   

"avgScore" : { "$avg" : "$score"}}}]))
avg_pos_score = mean_results[1]['avgScore']
avg_neg_score = mean_results[0]['avgScore']

mean_results 将包含字典实体列表(在本例中为 3 个实体 - neg、pos、neutral)。所以mean_results[0]指的是负面实体。 mean_results[1] 指正实体。 等等。 mean_results[1]['avgScore]=正实体的平均得分。 等等...

关于python - alchemyapi-recipes-twitter - 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29698799/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com