Skip to content
Advertisement

Pandas Dataframe datetime slicing with Index vs MultiIndex

With single indexed dataframe I can do the following:

JavaScript

Date time slicing works when you give it a complete day (i.e. 2016-01-01), and it also works when you give it a partial date, like just the year and month (2016-01). All this works great, but when you introduce a multiindex, it only works for complete dates. The partial date slicing doesn’t seem to work anymore

JavaScript

ok, thats fine, but the partial date:

JavaScript

(I shortened the traceback).

Any idea if this is possible? Is this a bug? Is there any way to do what I want to do without having to resort to something like:

JavaScript

Any tips, comments, suggestions, etc are MOST appreciated! I’ve tried a lot of other things to no avail!

Advertisement

Answer

Cross-section should work:

JavaScript

Documentation: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.xs.html

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement