I am working on time series data and want to arrange data belonging to same month in a contiguous fashion. Please look at the code.
from pandas_datareader import data as web
from datetime import datetime
from pandas.tseries.offsets import Day, MonthEnd
stock= web.DataReader('AAPL',data_source='google',start='1/1/2008',
end='12/31/2009')
a1=stock['Close'].resample('M').apply(lambda x: x[-1])
a2=a1[(a1.index.month==1)]
The last line accomplishes what I want, I am wondering if there is an efficient way of doing this as I have to repeat the same line for all the months. Thanks in advance