I am new to python and i want to understand how the execution takes place in a DataFrame. let's try this with an example from the dataset found in the kaggle.com(Titanic: Machine Learning from Disaster). I wanted to replace the NaN value with the mean() for the respective sex. ie. the NaN value for Men should be replaced by the mean of the mens age and vice versa. now i achieved this by using this line of code
_data['new_age']=_data['new_age'].fillna(_data.groupby('Sex')['Age'].transform('mean'))
my question is, while executing the code, how does the line knows that this particular row belongs to male and the NaN value should be replaced by the male mean() and female value should be replaced by the female mean().
