pbpython icon indicating copy to clipboard operation
pbpython copied to clipboard

Handling Missing values

Open harsh47 opened this issue 7 years ago • 0 comments

I think this fixes the problem of missing values. Is it correct way of handling missing values ?

def wavg(group, avg_name, weight_name):
    import numpy as np 
        group=group[np.isfinite(group[avg_name])] # ignores missing values 

    d = group[avg_name]
    w = group[weight_name]
    try:
        return (d * w).sum() / w.sum()
    except ZeroDivisionError:
        return d.mean()

harsh47 avatar Nov 04 '18 09:11 harsh47