我有一个数据集,此列在不同的列中包含NaN值。我想获取每列的平均值并覆盖其自己列的平均值中的NaN值。
#my dataset
arr = np.array([[10,20,np.nan],[5,np.nan,np.nan],[21,np.nan,10]]) #np.nan = NaN Values
df = pd.DataFrame(arr,index = ["İndex1","İndex2","İndex3"], columns = ["column1","column2","column3"])
#Solution
#list comprehension and use lambda
anonymousfunction = lambda dataframe: [dataframe[cNAME].fillna(value = dataframe[cNAME].mean(),inplace = True) for cNAME in dataframe.columns]
anonymousfunction(df)
print(df.head())