Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas select discontinuous dataframe date slices?

Tags:

python

pandas

I have a pandas DF with datetime index: this select works fine

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

but I'd 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 "unhashable type" and this gives me a string

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

Is there a 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
like image 804
dartdog Avatar asked Feb 14 '23 10:02

dartdog


1 Answers

threeyrs = pd.concat([actdf['01/01/2009':'12/01/2009'], actdf['01/01/2011':'12/01/2012']])
like image 185
U2EF1 Avatar answered Feb 17 '23 01:02

U2EF1