Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
List of Equity Variables from Dataframe

Hi there, when I run this chuck of code, I obtain a column with the closing prices with the name of the equities. I want to extract the names of all the equities in a list. How do I do that?

pipe = Pipeline(  
    columns={}'Close': USEquityPricing.close.latest},  
    screen=Q500US()  
)
stock_500_close = run_pipeline_chunks(pipe, '2006-01-03', '2014-12-31')  
2 responses

There's a dataset for that. Look at the Morningstar fundamentals 'company reference' category ( https://www.quantopian.com/help/fundamentals#company-reference ). There's a couple of name fields. Maybe 'short_name' is what you want. So simply add another column to your pipeline.

from quantopian.pipeline.data import morningstar as mstar

 pipe = Pipeline(  
    columns={  
            'Close' : USEquityPricing.close.latest,  
            'Name' : mstar.company_reference.short_name.latest,  
             },  
    screen=Q500US()  
    )  
stock_500_close = run_pipeline_chunks(pipe, '2006-01-03', '2014-12-31') 

If you want the names as a list you can use the 'tolist() method.

list_of_names = stock_500_close['Name'].tolist()

This list may contain duplicates. These can be eliminated by turning it into a python set or use numpy.unique(). Just depends upon what you want to do with the names.

Thank you so much Dan!