Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
filtering symbols where percent changes are greater than some threshold

Hello,

I am new to python so apologies for the newbie question, I have a dataframe containing pct changes of prices for a list of equities, I would like to only select those equities (note the equities are columns in the dataframe) where the price changes are below some threshold. Is there a simple pythonic way of applying a filter to a dataframe to do this?

Regards,
Mark

1 response

I believe I solved my own question, here is my solution if anyone is interested,

 #get transpose of dataframe  
df = df.transpose()  
#convert values that are above or below cutoff level to nan  
df = df[df > -1.0 * context.price_spike_cutoff ]  

df = df[df < context.price_spike_cutoff ]
#remove rows with nan
df = df.dropna(how='any')
#convert back to original structure
df = df.transpose()

any suggested improvements are welcome.

Regards,
Mark