suppose i have a sample code like this
_d=pd.DataFrame([[1,2,3],[4,np.nan,6],[np.nan,np.nan,8]],columns=['x','y','z'])
now, i have a function which checks for the value and assigns a desired value according to the scenerio
def handling_nan(_d):
if _d['x']==1.0:
return 100
else:
return _d
when i use this, in my below code,
_result=_d.apply(lambda x:handling_nan(x))
_result
i am getting error
KeyError: ('x', 'occurred at index x')
UPDATE A :
well, in short, i am using the dataset from kaggle.com ie. Titanic: Machine Learning from Disaster and in that dataset, i want to introduce a new column with condition something like this.
if male and the age is NaN then insert the mean() age of men instead of NaN and if female and the age is NaN, then insert the mean() of the total female age instead of NaN