答案 0 :(得分:0)
我通常这样做:
columnsWithNa = ['column1', 'column2']
for column in columnsWithNa :
df[column].fillna(df[column].mean()[0], inplace = True)
答案 1 :(得分:0)
# To read data from csv file
Dataset = pd.read_csv('Data.csv')
# To get values in variable 'X'
X = Dataset.iloc[:, :].values
# To calculate mean use imputer class
from sklearn.preprocessing import Imputer
imputer = Imputer(missing_values='NaN', strategy='mean', axis=0)
imputer = imputer.fit(X[:, :])
X[:, :] = imputer.transform(X[:, :])
答案 2 :(得分:0)
您可以使用此字段将各列各自的NaN
填充到mean()
中:
y12N = y12N.apply(lambda x: x.fillna(x.mean()))