This question is a continuation of pandas re-indexing with missing dates
I want to compute the sum of the values for the most recent 3 months (2015-12, 2015-11, 2015-10). If a stock doesn't have sufficient data i.e. has none,1 or 2 of the 3 months then I want that the value of that sum to be NaN.
I can slice and perform a group by and sum but this doesn't give me what I want since it may have excluded stocks that didn't have any data in this three month period and then does not account for stocks that have 1 or 2 months.
I imagine I need a multi loc statement but I've tinkered around and have not been able to get the results I want.
df2.loc[idx[:,datetime.date(2015,10,1):datetime.date(2015,12,1)],:].groupby(level=0).sum()