Any Pandas dataframe experts? Support/Resistance code

In that link, you will find a function that returns a series of supports and resistances for a given datasets of lows and highs.

Every single time I try to use this, the data returned is always empty. I isolated it to a ‘SettingWithCopyWarning’ issue that arises at line 76 and 78 of that file (when trying to set a value at the index of df[‘sup’] and df[‘res’].)

Anyone understand how to set values to dataframes without that error? If I remove the x and put a single integer, it will actually write to the index location. Would appreciate some help.

Hi,
ran the code. it has a lot of NaNs because that’s what it does when no resistane or support, but it seems to work
no issue with df['sup'].iloc[x] = sup

here’s a code example

api = tradeapi.REST(key_id=ALPACA_API_KEY,
                    secret_key=ALPACA_SECRET_KEY)
NY = 'America/New_York'
df = api.get_barset('AAPL', '1Min', start=pd.Timestamp('2020-09-26', tz=NY).isoformat(), end=pd.Timestamp('2020-09-30', tz=NY).isoformat()).df
print(supres(df['AAPL']['low'], df['AAPL']['high'])[456:])

this is what I get:
image

EDIT: Had a dumb issue on my end, it seems to work now.

Hope someone finds that code worthwhile!

The first thing you should understand is that SettingWithCopyWarning is a warning, and not an error. The real problem behind the warning is that it is generally difficult to predict whether a view or a copy is returned. In most cases, the warning was raised because you have chained two indexing operations together. The SettingWithCopyWarning was created to flag “chained assignment” operations. This is made easier to spot because you might be used [] (square brackets) twice, but the same would be true if you used other access methods such as .loc[] , .iloc[] and so on.

Moreover, you can change the behaviour of SettingWithCopyWarning warning using pd.options.mode.chained_assignment with three option “None/raise”/“warn”.