简体   繁体   English

如何使用fillna返回pandas DataFrame中相应列的平均值

[英]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.

相关问题 如何使用pandas数据帧中第一行和相应行之间的列的平均值填充特定值 - How to fill a particular value with mean value of the column between first row and the corresponding row in pandas dataframe Pandas Dataframe - Fillna 按月平均 - Pandas Dataframe - Fillna with Mean by Month Pandas dataframe由一些值组成 - Pandas dataframe fillna by some value 使用其他已知列值的Pandas Dataframe fillna() - Pandas Dataframe fillna() using other known column values Python Pandas DataFrame Fillna在不同数据框中具有列 - Python pandas dataframe fillna with column in different dataframe 如何正确使用fillna()作为熊猫数据框中的日期时间列(不起作用)? - How to correctly use fillna() for a datetime column in pandas dataframe (not working)? 如何将 numpy fillna() 和 numpy.where() 用于 Pandas DataFrame 中的列? - How to use numpy fillna() with numpy.where() for a column in a pandas DataFrame? fillna 通过引用另一列但使用 pandas 复制相同的列值 - fillna by referring another column but copy same column value using pandas 使用 Pandas 查找列的最大值并返回相应的行值 - Find maximum value of a column and return the corresponding row values using Pandas 如何根据变化的列值pd.fillna(mean())? - How to pd.fillna(mean()) acccording to a column value which changes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM