Pandas choose intermittent pieces of data in data mode?

I have pandas DF with datetime index: this choice works fine

threeyrs=actdf['01/01/2010':'12/31/2012']

but I would like to get something like this (to exclude 2010):

threeyrs=actdf['01/01/2009':'12/01/2009','01/01/2011':'12/01/2012']

which gives me a "fixed type" and it gives me a string

threeyrs=actdf['01/01/2009':'12/31/2009'],actdf['01/01/2011':'12/31/2012']

Is there any convenient way? dataFrame looks like

            Units
date    
2000-05-01   3041
2000-06-01   3079
2000-07-01   2455
2000-08-01   2671
2000-09-01   2220
+4
source share
2 answers
threeyrs = pd.concat([actdf['01/01/2009':'12/01/2009'], actdf['01/01/2011':'12/01/2012']])
+4
source

0.12 and 0.13

In [57]: df[((df.index>Timestamp('20000801')) & (df.index<=Timestamp('20000901'))) | ((df.index>Timestamp('20000501')) & (df.index<=Timestamp('20000601')))]
Out[57]: 
            units
date             
2000-06-01   3079
2000-09-01   2220

[2 rows x 1 columns]

Only 0.13

In [58]: df.query('(date>20000801 & date<=20000901) | (date>20000501 & date<=20000601)')
Out[58]: 
            units
date             
2000-06-01   3079
2000-09-01   2220

[2 rows x 1 columns]
+4
source

All Articles