I have a DataFrame with a MultiIndex of type (int, datetime). I want to set the entries of the column 'actual_12b1' that are 0.0 to NaN, but only if 'begdt' (the second level of the MultiIndex) is in 1998 or before. After some trial and error, I ended up with to following code:
year_start1999 = datetime(year=1999, month=1, day=1).date()
cond1 = data.index.get_level_values('begdt') < year_start1999
cond2 = data.actual_12b1 == 0.0
data.actual_12b1[cond1 * cond2] = np.nan
The code works, but it seems overly complicated. As I'm new to pandas (and confused by all that slicing/filtering), I thought someone might be able to suggest a cleaner way of achieving the same result.