kev1n
kev1n

Reputation: 400

Parsing information out of a pandas multi-index

From this pandas data frame, I am trying to parse out all the values corresponding to the date of '2019-1-02' for each ticker,

                   (Dividends + Share Buyback) / FCF  ...  Price to Book Value
Ticker Date                                           ...                     
A      2007-01-03                                NaN  ...                  NaN
       2007-01-04                                NaN  ...                  NaN
       2007-01-05                                NaN  ...                  NaN
       2007-01-08                                NaN  ...                  NaN
       2007-01-09                                NaN  ...                  NaN
...                                              ...  ...                  ...
ZYXI   2019-10-07                           0.181382  ...            29.880555
       2019-10-08                           0.181382  ...            27.452610
       2019-10-09                           0.181382  ...            27.188180
       2019-10-10                           0.181382  ...            26.779516
       2019-10-11                           0.181382  ...            28.101665

should return:

                   (Dividends + Share Buyback) / FCF  ...  Price to Book Value
Ticker Date                                           ...                     
A      2019-1-02                                5     ...                  6
AA     2019-1-02                                etc   ...                  etc
...    ...                                      ...   ...                  ...

I have tried:

df_signals.query('Date == 2019-1-02')

returns:

Empty DataFrame
Columns: [(Dividends + Share Buyback) / FCF, Asset Turnover, CapEx / (Depr + Amor), Current Ratio, Dividends / FCF, Gross Profit Margin, Interest Coverage, Log Revenue, Net Profit Margin, Quick Ratio, Return on Assets, Return on Equity, Share Buyback / FCF, Assets Growth, Assets Growth QOQ, Assets Growth YOY, Earnings Growth, Earnings Growth QOQ, Earnings Growth YOY, FCF Growth, FCF Growth QOQ, FCF Growth YOY, Sales Growth, Sales Growth QOQ, Sales Growth YOY, Earnings Yield, FCF Yield, Market-Cap, P/Cash, P/E, P/FCF, P/NCAV, P/NetNet, P/Sales, Price to Book Value]
Index: []

Upvotes: 2

Views: 51

Answers (1)

Cameron Riddell
Cameron Riddell

Reputation: 13407

You'll want to use the DataFrame.xs(...) method for this. This should work for your dataframe:

df.xs("2019-1-02", level="Date")

Upvotes: 3

Related Questions