0
df [row、 'avg']行の平均と列の平均( 'impute [col]')に対応するオフセットでヌル値を代入しようとしています。メソッドを.mapと並列化する方法はありますか?または、ヌル値を含むインデックスを反復処理するより良い方法がありますか?Python Pandas Null値の代入
test = pd.DataFrame({'a':[None,2,3,1], 'b':[2,np.nan,4,2],
'c':[3,4,np.nan,3], 'avg':[2.5,3,3.5,2]});
df = df[['a', 'b', 'c', 'avg']];
impute = dict({'a':2, 'b':3.33, 'c':6 })
def smarterImpute(df, impute):
df2 = df
for col in df.columns[:-1]:
for row in test.index:
if pd.isnull(df.loc[row,col]):
df2.loc[row, col] = impute[col]
+ (df.loc[:,'avg'].mean() - df.loc[row,'avg'])
return print(df2)
smarterImpute(test, impute)
それがうまくいった!ありがとう、私は.combine_firstメソッドを知らなかった。 – MyopicVisage