Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Notebook: Conditionally selecting N rows of pd data to plt

Hi all, a simple question regarding plotting. I have a price df and i want to plot price for the next N days prices but do so only if price std is above a certain value, basically this (i tried selecting next N rows but it does not work):

Plot next X days price IF std is above N

plt.plot(price_df["std"] > N, price_df["close"][:X])  

Thanks for your time

3 responses

Bumping this back up - thanks to anyone who can help

Bumping this back up yet again - Thanks to anyone who can help!

Hi Darell,

A simple solution would be to filter your data before passing it in to plt.plot()

If price_df is a reference to a Pandas Dataframe, you can do this fairly easily

The code would look something like this

price_df_filtered = price_df[price_df['std'] > your_desired_value] #returns all rows in criteria  
plt.plot(price_df_filtered["close"][:desired_days])  

If you want to do more complex filtering, you should look into Quantopian's Pipeline API

Cheers
Matt