我有一个数据框,如下所示:
id created_on operation property_type place_with_parent_names floor rooms expenses price_aprox_local_currency description title table_name days_on_market
59176 172cdc2cdc7f59b9029c0cb758474b4eb39edcd0 2015-01-16 sell house |México|Nuevo León|Monterrey| NaN NaN NaN 5735793.85 Casa en venta en Cumbres 2do. Sector. 3 habita... Casa en Venta en Monterrey 201501 15
64175 f370552ac7e53400d0ffb7ba3624bacace9b5c37 2015-01-05 sell house |México|Baja California|Playas de Rosarito| NaN NaN NaN 3893406.00 Casa con excelente terreno y amplios espacios,... CASA EN VENTA ROSARITO 201501 26
64174 d388b6e389ec6124740fb515fbb950c7197b92c6 2015-01-05 sell house |México|San Luis Potosí|San Luis Potosí| NaN NaN NaN 446984.59 Excelente ubicacióna 6 minutos de Blvd. Rio Sa... PROYECTO: Villas de la Victoria, una PLANTA, ... 201501 26
我想按place_with_parent_names列进行分组,并且还要使用每个此类组的平均值来填写我的楼层,房间,费用和price_aprox_local_currency列中的NA值
到目前为止,我有:
single_price_listings2 = single_price_listings.groupby(["place_with_parent_names"])["floor", "rooms", "expenses", "price_aprox_local_currency", "days_on_market"].mean().transform(lambda x: x.fillna(x.mean()))
我将收到以下消息:
floor rooms expenses price_aprox_local_currency days_on_market
59176 4.673260 3.123693 1034.293750 5.735794e+06 15
64175 2.250000 NaN 235.000000 3.893406e+06 26
64174 2.240409 2.992894 1010.000000 4.469846e+05 26
我认为它可能在可能的情况下填充了NaN值,但是没有返回groupby()。mean()对象,如果我尝试在末尾抛出.mean(),我会得到提示单行(我想这是整个列中每一列的平均值)。