Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Filter/Mask Non-Financials

Just getting started on Quantopian and been working through tutorials. How do you filter (and ultimately mask) non-financial companies. Imported Sector but then tried to define "fin_sector = Sector.eq(103) to ID financials. Figured that then I could invert it to ID non-financials. Clearly that Sector.eq syntax is wrong, but what's the right syntax?

2 responses

One tiny error. Missed some parenthesis. Should be...

fin_sector = Sector().eq(103) 

One can also invert that to filter everything but the financial sector using the ~ operator.

not_fin_sector = ~Sector().eq(103) 

You need the parenthesis to first make an instance of the class "Sector". Then, once that's done, one can reference the 'eq' method of that instance. Can think of it like this...

# on two lines  
sector_object = Sector()  
fin_sector = sector_object.eq(103)


# on one line. Note that sector_object gets replaced by Sector() not just Sector (which is the class)  
fin_sector = Sector().eq(103)

Good luck.

Great! Thanks Dan! Just getting used to the coding here. Much appreciated