HI,
The screen link: https://app.dataquest.io/m/370/working-with-missing-data/3/filling-and-verifying-the-killed-and-injured-data
I´d like to check if I understand correctly the difference between newly introduced method Series.mask()
and the regular assigning values using Boolean mask (i.e. df.loc[df['col1'].isnull(), 'col1'] = 'Other'
) learnt in some Pandas introductory mission.
As far I´ve got it, when we use the latter one only we can update the values only with a single value and when we use the Series.mask()
method we can update the values with a single value or a matching value from a series that has identical index labels.
Considering the above true, in this mission we can use either of the methods to replace any numbers from total_killed
that aren’t equal to their equivalents in killed_manual_sum
with np.nan
:
killed['total_killed'] = killed['total_killed'].mask(killed['total_killed'] != killed_manual_sum, np.nan)
or
killed.loc[killed['total_killed'] != killed_manual_sum,
total_killed’] = np.nan`
And we can only use the Series.mask()
method in order to replace any null values from the total_killed
column with their equivalents from the killed_manual_sum
series:
killed['total_killed'] = killed['total_killed'].mask(killed['total_killed'].isnull(), killed_manual_sum)
Could anyone, please, confirm whether I understand it correctly or not?