When working with time series data in python, you frequently need to split the data into date ranges such as financial years.

For a full list of Pandas breaks see the documentation http://pandas.pydata.org/pandas-docs/stable/timeseries.html#anchored-offsets.  As an example, you can resample time series data into Australian financial years you use:


pandas.resample('(B)A(S)-JUN').sum()

Pandas has a lot of functionality for resampling time series data, but sometimes you need to role your own.

This little bit of code creates end of financial year dates for the last five years.


today = datetime.datetime.today()
#last five years
date_stops = []
date_stops.append(pd.datetime(today.year, 6, 30))
for i in range(1,6):
    date_stops.append(pd.datetime(today.year-i, 6, 30))
date_stops

or, in a one line list comprehension


date_stops = [pd.datetime(datetime.datetime.today().year-i, 6, 30) for i in range(6)]

date_stops