The right way to query a pandas MultiIndex

Viewed 8647

I've got a huge dataframe (13 million rows) which stocks and stock prices in. I've indexed them using MultiIndex(['stock', 'date']), where date has been parsed as a DateTime.

This means I can select price data based upon stock easily df.loc['AAPL'], and by specific day df.loc['AAPL'].loc['2015-05-05'].

What I want to know is, what is the fastest and most elegant accessor for getting all stock prices on a particular day (i.e. if the indices were reversed).

Currently I'm using df.xs("2015-05-05", level=1) - is that the right way? Is there a better/cleaner/faster way?

1 Answers
Related