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.
I want to compare max values (which are non Nan) with each other but only in the forward direction.
for example,
- 777.244202 will be compared with all other values of the "max" column which are higher than 777.244202
- print those rows which are having .618 Fibonacci retracement with 777.244202
Is there any simpler method in pandas that can do this?