Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Dataframe question - how to use multiple rows and columns to apply conditions in vectorized way?

I would like to make a new column called "trigger" in a dataframe. The trigger condition is based on three consecutive days bullish condition such as:

df["bullish"] = (df["price_change"] > 0)

I like to make:

df["trigger"] = (three consecutive day df["bullish"] is True, but I don't know how to do it)
Is it possible to make a trigger condition using 3 consecutive days in pandas vectorized way?

Do you have any suggestions?

I've attached a notebook for your exercise.

1 response

I think I figured it out.
The solution is shifting a column!