[Solved] how to fill NA with mean only for 2 or less consequective values of NA


Let’s try this

df["val1"] = df["val1"].transform(lambda x: x.fillna(x.mean(), limit=2))
df["val2"] = df["val2"].transform(lambda x: x.fillna(x.mean(), limit=2))
print df

Don’t forget to let us know if it solved your problem 🙂

1

solved how to fill NA with mean only for 2 or less consequective values of NA