I've started using Pandas for some large Datasets and mostly it works really well. There are some questions I have regarding the indices though
I have a MultiIndex with three levels - let's say a, b, c. How do I slice along index a - I just want the values where a = 5, 7, 10, 13. Doing df.ix[[5, 7, 10, 13]] does not work as pointed out in the documentation
I need to have different indices on a DF - can I create these multiple indices and not associate them to a dataframe and use them to give me back the raw ndarray index?
Can I slice a MultiIndex on its own not in a series or Dataframe?
Thanks in advance
For the first part, you can use boolean indexing using get_level_values
:
df[df.index.get_level_values('a').isin([5, 7, 10, 13])]
For the second two, you can inspect the MultiIndex object by calling:
df.index
(and this can be inspected/sliced.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With