I have a large data set of numbers which are embedded in documents. I want to extract them all, put them in an ordered list, and then return to each document its “pvalue”: which is its order in the sorted list divided by the length of the list.
I am having a lot of trouble figuring out how to do this within a python code.
movie_records = db.movies.find()
list=[]
for i in movie_records:
num = i["total_tickets"]
#put them all in a list, order the list
for i in movie_records:
number=i["total_tickets"]
tickets_pvalue= 1 - ( #position of number /len(list) )
shows.update({"id":i["id"]}, {'$set':{"total_tickets_pvalue":tickets_pvalue}})
Barring any knowledge of mongodb (you’d be better off doing the sorting by it, as suggested in the comments):