Is there a way to implement groupby with an aggregate function so the function ignores nan values?

User 5270 | 7/6/2016, 4:37:11 PM

groupedproducts = train.groupby('ProductID', operations = {'avgprice' : agg.AVG('priceproduct')})

Comments

User 91 | 7/8/2016, 3:26:18 PM

You can do so by changing the values in avg_price and price_product from a nan to a None and then perform an apply.

train['avg_price'] = train['avg_price'].apply(lambda x: x if x is not np.nan else None)

The None will get automatically ignored.