Data mart practie problem code causing error when imputing data



this is article link:

I’m facing an error while trying to perform imputation for Item_Weight as suggested:(I’ve tried in python 2.7 and 3.6)

data.loc[miss_bool,'Item_Weight'] = data.loc[miss_bool,'Item_Identifier'].apply(lambda x: item_avg_weight[x])

error :

C:\Users****************\envs\python27\lib\site-packages\pandas\core\indexes\base.pyc in get_loc(self, key, method, tolerance)
   2525                 return self._engine.get_loc(key)
   2526             except KeyError:
-> 2527                 return self._engine.get_loc(self._maybe_cast_indexer(key))
   2529         indexer = self.get_indexer([key], method=method, tolerance=tolerance)
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'FDP10'

Any solution would be much appreciated: Thank you.



The error it is showing for “FDP10”, I looked at the data and found that it is present in the “Item_Identifier” column but we are imputing values of “Item_Weight” column.

After looking at the code, I found a typo, this should be your code(look at the bold part) -

data.loc[miss_bool,‘Item_Weight’] = data.loc[miss_bool,‘Item_Weight’].apply(lambda x: item_avg_weight[x])

Let me know if you face any issues!

@jalFaizy what do you think?

Sanad :slight_smile:



I tried with ‘Item_Identifier’ also; it worked.

But only thing i changed is storing pivot table values to pandas series array.



I am still getting this error, Can any one help me on this problem.
thank you.


Hi @ganesh29,

Use capital s (S) in the word series.

pd.Series will work, pd.series will not.