Reputation: 113
I have an issue with the Average function in pymongo aggregate query.
I have a structure like this:
{'_id': ObjectId('5afd9c675e3a1f0e9b830510'),
'actor_gender': 'NaN',
'actor_id': 'NaN',
'actor_last_name': 'Safary',
'actor_name': 'Darsheel',
'actor_role': 'NaN',
'director_id': 'NaN',
'director_last_name': 'Khan',
'director_name': 'Aamir',
'movie_genre': 'Drama',
'movie_name': 'Taare Zameen Par',
'movie_rank': 8.5,
'movie_year': 2007}
When I compute this query:
coll.aggregate([{"$group":{"_id":{"movie_genre":"Drama"},
"avg":{"$avg":"$movie_rank"}}}])
I got this nan
on the average:
{'_id': {'movie_genre': 'Drama'}, 'avg': nan}
Upvotes: 1
Views: 343
Reputation: 206
Mongodb aggregation with nan values give NAN as output(https://jira.mongodb.org/plugins/servlet/mobile#issue/SERVER-27472) You must be having some nan values in the movie_rank field.
Upvotes: 1