0

I have a panda dataframe

import yfinance as yf
import numpy as np
from scipy.signal import argrelextrema
import matplotlib.pyplot as plt
import pandas as pd

n = 2
df = yf.Ticker("INFY.NS").history(period='400d', interval='1D')
df['max'] = df.iloc[argrelextrema(df1['Close'].values, np.greater_equal,order=n)[0]]['Close']
print(df)

I have created a column name max which has values as shown in the screenshot. The screenshot is only for reference. Sample data can be obtained by running the code above.

enter image description here

I want to compare max values (which are non Nan) with each other but only in the forward direction.

for example,

  1. 777.244202 will be compared with all other values of the "max" column which are higher than 777.244202
  2. print those rows which are having .618 Fibonacci retracement with 777.244202

Is there any simpler method in pandas that can do this?

sam
  • 18,509
  • 24
  • 83
  • 116
  • Please include sample data in a way that we can use, not as an image. See this [page](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) for help with this. – joao May 20 '21 at 04:48
  • @joao: attached 8 lines of code that can create sample data. The screenshot attached is only for reference. – sam May 20 '21 at 06:19
  • 1
    it's not clear to me what you want to do (third bullet in your list in the question): compare each non-Nan value to its _next_ non-Nan value or compare each non-Nan value to _all following_ non-Nan values? – Stef May 20 '21 at 10:51
  • each number will be compared with every number in the column that is larger – sam May 20 '21 at 10:56
  • @stef: updated the question in the easy form, please have a look – sam May 20 '21 at 11:45
  • Hm, the update makes it more difficult for me to understand, but as for the original question you could take the non-na values of the max column, convert them to numpy, devide them by its transposed and take the indices of the upper triangle elements in that matrix that are < 1. For your example I get 1849 row cominations where a later value is greater than a preceding one. If this is what you need I can write an answer, otherwise please explain. – Stef May 20 '21 at 12:17

0 Answers0