我有一个像这样的数据集
Item Cost
books NaN
books 12
books 12
books 12
pen 10
pen NaN
pen 10
pencil 8
pencil 8
pencil Nan
我想用相应项目的平均值替换“费用”列中的NaN。这是我想要的输出
Item Cost
books 12 (filled average of other rows where books=12)
books 12
books 12
books 12
有人可以告诉我怎么做吗?