Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How does one access elements of a pipeline index?

I'm having issues accessing a portion of a pipeline index. I'm running a correlation against a target symbol, then sorting for highest corr. I want to pull the candidate symbol out of the index. I can't figure out how to do this. Any thoughts/suggestions on how to get the 'XRT' out of below would be appreciated. Note - fp values are a separate column, just looks merged here. tia

                                            Rolling Correlations  

2017-02-23 00:00:00+00:00 Equity(32275 [XRT]) 0.918131
2017-02-22 00:00:00+00:00 Equity(32275 [XRT]) 0.914572
2017-02-01 00:00:00+00:00 Equity(11086 [AEO]) 0.912347
2017-02-24 00:00:00+00:00 Equity(32275 [XRT]) 0.912347
2017-02-21 00:00:00+00:00 Equity(32275 [XRT]) 0.907453

5 responses

Hi Chad,

I'm having a little bit of trouble understanding the context of the question. Specifically, I can't really help without knowing the type of the data structure. It might help if you shared some of the code that you used to get that data.

Based on the shape, it looks like you might be working with a pipeline in research that produced a DataFrame with a MultiIndex. If that's the case, and you want the first equity from the top row, you should be able to do:

df.index.get_level_values(1)[0]  

This won't work in an algorithm, nor do I think it's the right approach here. Ideally, you'll probably want to do something like:

df.index[df['Rolling Correlations'] == df['Rolling Correlations'].max()].get_level_values(1)[0]  

This will get you the Equity with the highest Rolling Correlation in the DataFrame (no need to sort in this case).

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Thank you for the suggestion. I am running pipeline in research environ. I think I'm ending up with a series, the index being these strange pipeline elements.
I've attached a copy of notebook. Please excuse lack of elegance in the code. It's a kludged piece in progress.
Currently I'm sorting output so I can manual view it. I believe I'm getting some kind of a series, a column of fp 'rolling correlation' indexed by pipeline. So once I sort or max r3 object, i need to pull Equity name out of the index corresponding index so i can then get_data on it and such. Thanks again for your help/any insight you can provide.

print x.head(5)

Chad,

The result is indeed a pandas DataFrame with a MultiIndex. My suggested solution above should work.

If you haven't seen it yet, I would recommend going through the Pipeline Tutorial to get a better sense of how Pipeline works. It's definitely more focused on Pipeline construction, but there are some parts that discuss the output as well.

OK, got it with:
x = r3.index.get_level_values(1)
z = x[0].symbol

The multiIndex is new to me. Thx again for your time/help.

This helped me Chad, Thanks!