Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Filtering Boolean Operators

Hello,

I am having trouble filtering boolean operators. How might I do this? i can't seem to find the right documentation. I have a variable with stocks marked true if they meet the criteria for selection and false if they don't. I need to remove the false ones and keep the true ones and store them into a pd.DataFrame.

Thank you,
Dante Migale

3 responses

Pandas Boolean indexing?

>>> d = pd.DataFrame({'x':[1, 2, 3, 4, 5], 'y':[4, 5, 6, 7, 8]})  
>>> d  
   x  y  
0  1  4  
1  2  5  
2  3  6  
3  4  7  
4  5  8  
>>> d[d['x']>2]  
   x  y  
2  3  6  
3  4  7  
4  5  8  

I have a variable with stocks marked true if they meet the criteria for selection and false if they don't.

What is the data structure of your variable? Is it a Python dictionary? List? Something else?

Thank you Luca and Grant! I have figured it out, but I appreciate the help!