ISSUE
I am performing data cleansing. I have calculated a column mean based on conditions fed into the .loc()
function. Storing this output in the z variable is producing a (1,1) dataframe and throwing an incompatibility error when I try to assign it to a missing value.
WHAT'S BEEN TRIED
Input
a = train[['LotFrontage', 'MSSubClass', 'MSZoning', 'Street',
'LotShape']]
z = train.loc[((train.MSSubClass == 190) &
(train.MSZoning == 'RL') &
(train.LotShape == 'IR1'))]
.agg({'LotFrontage': ['mean']})
a.LotFrontage[335] = z
Output
ValueError: Incompatible indexer with DataFrame
QUESTIONS
- Is it possible to store the
.mean()
output as an integer in z to fix this issue? - If above is not possible, is there a different method I should be using to replace the missing
LotFrontage
value with the calculated mean?