[英]How to return the mean value of the corresponding column in a pandas DataFrame using fillna
How to return the mean value of the corresponding column in a pandas DataFrame using fillna.如何使用fillna返回pandas DataFrame中相应列的平均值。 Basically, if I have column total_bill and data_usage for example, I want to fill all the NaN in total_bill column with the mean value of all entries in total_bill column.
基本上,如果我有列 total_bill 和 data_usage ,我想用 total_bill 列中所有条目的平均值填充 total_bill 列中的所有 NaN 。 In a like manner, fill all the NaN in data_usage column with the mean value of all entries in data_usage column.
以类似的方式,用 data_usage 列中所有条目的平均值填充 data_usage 列中的所有 NaN。
Do you mean by:你的意思是:
for col in df.columns:
df[col] = df[col].fillna(df[col].mean())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.