Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Extracting indices from Pipeline DataFrame as string tickers in a list.

Greetings Everyone!

I'm running into an issue in my research notebook regarding multi-index data frames from my pipeline.

My notebook is fairly simple, I have a parameter of stocks that get filtered down given a range of digits. I then use the "bucket of stocks", AKA dataframe, that the pipeline crunched out followed by creating a list of tickers using the index. Using this list, I would like to feed it to more pipelines to conduct deeper analysis.

In the notebook that I shared, the analysis I would like to have conducted is a correlation test using my new bucket of stocks. However, I can't seem to figure out how to extract the indices as a list using only the tickers in string format (so I can pass it through the price pipeline). I know this is fairly trivial but I would greatly appreciate some guidance or clarification on my code.

Here is my workflow:
(Pipeline one(stock bucket) > Extract indices (stock tickers) into a variable > Pipeline two (using my "stock bucket" to feed stocks into correlation analysis test)

Again, I would love critique on my notebook. Stay healthy and safe everyone!

Thank you,
Andres 'dre'

6 responses

I have been searching everywhere for this and it seems a lot of people are running into the same roadblock not knowing what to do. I hate to double post without providing any value or proper follow-up, but has anyone solved this or know a solution?

Thanks for your response Kevin, I checked the notebook you sent me. While indeed useful information, I don't see where he extracts the indices from his multi-level dataframe.

Hey sorry...I think this is the part you’re interested in, my bad.

https://www.quantopian.com/tutorials/getting-started#lesson4

https://www.quantopian.com/posts/how-to-change-asset-objects-to-string-in-dataframe-returned-from-run-pieline


# Import prices function  
from quantopian.research import prices

# Get list of unique assets from the pipeline output  
asset_list = pipeline_output.index.levels[1].unique()

# Query pricing data for all assets present during  
# evaluation period  
asset_prices = prices(  
    asset_list,  
    start=period_start,  
    end=period_end  
)

Hey Kevin, thank you so much, solved the issue for me. I could of sworn I've tried something similar but was off by so close! Many thanks again. For anyone reading this in the future, do not attach .unique() at the end of : asset_list = pipeline_output.index.levels[1]

No prob! 😀