I’m a Python newbie and have the following Pandas dataframe - I’m trying to write code that populates the ‘signal’ column as it is below:
| Days | long_entry_flag | long_exit_flag | signal | 
|---|---|---|---|
| 1 | FALSE | TRUE | |
| 2 | FALSE | FALSE | |
| 3 | TRUE | FALSE | 1 | 
| 4 | TRUE | FALSE | 1 | 
| 5 | FALSE | FALSE | 1 | 
| 6 | TRUE | FALSE | 1 | 
| 7 | TRUE | FALSE | 1 | 
| 8 | FALSE | TRUE | |
| 9 | FALSE | TRUE | |
| 10 | TRUE | FALSE | 1 | 
| 11 | TRUE | FALSE | 1 | 
| 12 | TRUE | FALSE | 1 | 
| 13 | FALSE | FALSE | 1 | 
| 14 | FALSE | TRUE | |
| 15 | FALSE | FALSE | |
| 16 | FALSE | TRUE | |
| 17 | TRUE | FALSE | 1 | 
| 18 | TRUE | FALSE | 1 | 
| 19 | FALSE | FALSE | 1 | 
| 20 | FALSE | FALSE | 1 | 
| 21 | FALSE | TRUE | |
| 22 | FALSE | FALSE | |
| 23 | FALSE | FALSE | 
My pseudocode version would take the following steps
- Look down the [‘long_entry_flag’] column until entry condition is True (day 3 initially)
- Then we enter ‘1’ into [‘signal’] column every day until exit condition is True [‘long_exit_flag’]==True on day 8
- Then we look back to [‘long_entry_flag’] column to wait for the next entry condition (occurs on day 10)
- And again we enter ‘1’ into [‘signal’] column every day until exit condition is True (day 14)
- etc.
What are some ways to populate the ‘signal’ column rapidly if possible (using vectorisation?)?
This is a subset of a large dataframe with tens of thousands of rows, and it is one of many dataframes being analysed in sequence.
 
     
     
     
     
    