Shakti
Shakti

Reputation: 2033

How to check for a range of values in a pandas dataframe?

I have a pandas dataframe in which I want to check if a future value is greater than the given value for a range of future dates. For example

np.where((df['Close'].shift(-1) - df['Close'])  > 0 , 1, 0)

This will give me if next value is greater than current value, I want to check if current value is greater than say next 5 values ?

Upvotes: 1

Views: 758

Answers (1)

maxymoo
maxymoo

Reputation: 36545

You could use pd.rolling_max for this, something like

window = 5
pd.rolling_max(df['Close'], window).shift(-window) - df['Close'])  > 0 

Upvotes: 1

Related Questions