I have a data frame with index (ID, Date), where I would like to select all observations within a certain timeframe (e.g. 06-1988 : 11-1988). In case not all observations are present within the timeframe for a certain ID, I would still like to include the ones that are present.
Visualization of my data frame to give a better idea: (The panel is not balanced)
Var1 Var2
ID Date
10113 2010-07 24.7000 24.7000
2010-08 25.2600 24.7000
2010-09 25.2800 25.2800
2010-10 25.3700 25.3700
10223 2010-09 24.7000 24.7000
2010-10 25.2600 25.2600
2011-11 25.2800 25.2800
2011-12 25.3700 25.3700
2012-01 25.2900 25.2900
For instance I would want all observations between 2010-09 and 2011-12, I would want to get the following output:
Var1 Var2
ID Date
10113 2010-09 25.2800 25.2800
2010-10 25.3700 25.3700
10223 2010-09 24.7000 24.7000
2010-10 25.2600 25.2600
2011-11 25.2800 25.2800
2011-12 25.3700 25.3700
I also have a series with the same two multi-index settings, and there the following command worked:
X.loc[:,'1988-06':'1998-07']
If I wanted all observations between 1988-06 and 1998-07 for all ID's. When I try this same approach for the Dataframe, I get a KeyError.
Is it possible to do the same with a Dataframe?