ranking values wrt dictionary values in python -
i trying rank dictionary based on it's values. example:
score = {'178413': 0.0, '178414': 0.0}
after operation should be
score = {'178413': 1.5, '178414': 1.5}
i tried
import scipy.stats ss temp = ss.rankdata(score.values()) print temp temp = [1.5 1.5]`
so rank of score.values equal temp. want replace corresponding temp values in dictionary values placed can't seem place in dictionary.
**complete code tried **
so following way , placing in dictionary. feel it's not correct
import scipy.stats ss score = {'178413': 3, '178414': 0.0} inv_score = {y:x x,y in score.iteritems()} rank_val = ss.rankdata(score.values()) count = 0 in score.values(): id = inv_score[i] score[id] = rank_val[count] count += 1
output : score = {'178413': 2.0, '178414': 1.0}
code fail if input score {'178413': 0.0, '178414': 0.0}
Comments
Post a Comment