Back to Community
KeyError: 'the label [ Equity(2 [ARNC])] is not in the [index]'

Dear Expert,

I have the above error when I try to print a specific row's name.

     print('check2', pipeline_data['combined_data'].iloc[0])  
>> False

    print('check4', pipeline_data['combined_data'].index)  
>> ('check4', Index([    Equity(2 [ARNC]),    Equity(24 [AAPL]),    Equity(41 [ARCB]),  
           Equity(52 [ABM]),     Equity(62 [ABT]),     Equity(64 [ABX]),  
          Equity(67 [ADSK]),     Equity(76 [TAP]),     Equity(88 [ACI]),  
         Equity(110 [RAMP]),  
        Equity(39073 [CIE]),  Equity(39079 [KRA]),  Equity(39111 [PPC]),  
        Equity(39160 [SYA]), Equity(39171 [MSGN]), Equity(39202 [SLRC]),  
        Equity(39204 [PDM]),   Equity(39347 [ST]),  Equity(39434 [PRI]),  
       Equity(39495 [SDRL])],  
      dtype='object', length=1811))

    print('check5', pipeline_data['combined_data'].loc['    Equity(2 [ARNC])'])  
>>KeyError: 'the label [ Equity(2 [ARNC])] is not in the [index]'  

Also, print function seem to be able to print a subset on the IDE screen. Is it possible to print the all the values out?

Thanks for your help

3 responses

The dataframe is indexed by the equity objects and not simply the equity string name. Try this:

    print('check5', pipeline_data['combined_data'].loc[symbol('ARNC')])  

depending upon if this is in an algo (ie the IDE) or a notebook (ie the research environment) you may need to use the 'symbols' method instead. In any case get a reference to the security object and use that instead of a string.

It works within "rebalance" function in the algo but couldnt work in the "make_pipeline".

    combined_data= (    factor1.loc[symbol('MTRN')]  

 >>> AttributeError: 'NumExprFactor' object has no attribute 'loc'  

It appears from your code that 'factor1' is a factor object (or more specifically a NumExprFactor object). Factors are not dataframes and therefore don't have the 'loc' method. That is what the error is telling you.

One defines a pipeline and the associated factors and filters first (in this case it appears to be defined in the 'make_pipeline' function). When the pipeline is run it returns a dataframe. That returned dataframe can be manipulated just like any other dataframe. This is why what you are trying to do works in the rebalance method.

If you want to select a specific security in the pipeline definition then consider using a StaticAssets filter (see )