I have a data frame. One column is called fractal. It has 0's or 1's in which the 1's represents a fractal. Here is the output of np.flatnonzero to get an idea of the frequency of fractals:
np.flatnonzero
[ 15 32 77 93 110 152 165 185 194 201 223 232 245 264 294 306 320 327
347 370 380 391 409 436 447 460 474 481 500 534 549 561 579 586 599 620
627 641 653 670 685 704 711 758 784]
There's another column that has a high price, df['high'] that contains the daily high prices of a financial instrument.
I want to add a column to the database, df['f_support'] that contains high prices relating to the high price of the last fractal.
The high price is 2 rows before the fractal signal. In other words, the column would contain the same high price until another fractal signal, then a new high price would start filling the column.
Looking at the output of np.flatzero the column f_support should contain this:
| f_support | value |
|---|---|
| 0–14 | nothing |
| 15–31 | df['high'].iloc[13] |
| 32–77 | df['high'].iloc[30] |
and so on.
I hope I've conveyed this so it makes sense. There's probably an easy way to do this but it's beyond my present scope.