I have a large dataframe with a ~10 levels multiindex and timeseries data, like this:
country Elbonia ... Elbonia ...
state Upper Elbonia ... Lower Elbnonia ...
city Krschmsh ... Chkchk ...
elevation 1400 ... 800 ...
...
importance high ... mid ...
visit yes ... maybe ...
Date
1930-01-01 Nan ... 500 ...
1930-02-01 358,2 ... 501 ...
and I can select things very straightforward and readable with .xs, like Chkchk = Elbonia.xs('Chkchk', level='city', axis=1, drop_level=False) and have one new, smaller dataframe. So far, so good. If I need more than one city, I could grab the whole state of Upper Elbonia with Elbonia.xs('Upper Elbonia', level='state'... or all the cities with a high importance and so on.
But let's say I need a dataframe that contains both, Krschmsh in Upper Elbonia and Chkchk in Lower Elbonia.
The xs documentation says "xs also allows selection with multiple keys", but apparently, the multiple MUST be applied to both, the key and the level. The obvious Elbonia.xs(('Krschmsh', 'Chkchk'), level='city', axis=1, drop_level=False) fails with a KeyError.
Now I'm not the first to notice this, and here are a bunch of solutions for simple dataframes, but those don't work for me*.
So what is the reason that .xs can't do this seemingly very simple and obvious selection of two keys from one level?
*I'm just selecting each city as one dataframe, and then concat them together. The solutions linked above are probably better but for this code it is very important that is says what is selected and from which level of the large multiindex, for which I have only found only .xs as an easy and straightforward solution.