0

I am about few weeks old with Python. I am new to both object oriented and Python. My experience is limited to COBOL. I can iterate over the df in the old fashioned clumsy way using nested for-loop, but I'm sure there is an elegant way out.

mydf: DataFrame with index and 4 cols. datetime, close, crossover, NearestCrossoverClose:
Sample DataFrame

The crossover column has Y in case my technical analysis line has crossed over Until the next crossover happens this col has NaN values

I need to get the value of close associated with Crossover=Y and following Crossover=NaN into the NearestCrossoverClose=the value of the close when the last crossover took place.

PS: It could be nearest=1 (first nearest crossover close) or nearest=n integer. Default is 1.

Henry Ecker
  • 31,792
  • 14
  • 29
  • 50
Kris
  • 1
  • Please do not link or embed external images of source code or data. Images make it difficult to efficiently assist you as they cannot be copied and offer poor usability as they cannot be searched. See: [Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/q/285551/15497888) If you need assistance formatting a small sample of your DataFrame as a copyable piece of code for SO see [How to make good reproducible pandas examples](https://stackoverflow.com/q/20109391/15497888). – Henry Ecker Oct 29 '21 at 19:27

0 Answers0