Private
Public Access
1
0

added weighted average - rScore now uses weighted average

This commit is contained in:
Sander Roosendaal
2018-02-24 14:23:48 +01:00
parent f4a66a78cf
commit 57eee137ce
4 changed files with 27 additions and 7 deletions

View File

@@ -319,3 +319,15 @@ def my_dict_from_instance(instance,model):
thedict[fname] = (verbosename,value)
return thedict
def wavg(group, avg_name, weight_name):
""" http://stackoverflow.com/questions/10951341/pandas-dataframe-aggregate-function-using-multiple-columns
In rare instance, we may not have weights, so just return the mean. Customize this if your business case
should return otherwise.
"""
d = group[avg_name]
w = group[weight_name]
try:
return (d * w).sum() / w.sum()
except ZeroDivisionError:
return d.mean()