I have a dataframe with multiple columns and trying to find out local minima and maxima for only one of the column data. For which, I am using below code
df['min'] = df.histo[(df.histo.shift(1) > df.histo) & (df.histo.shift(-1) > df.histo)]
df['max'] = df.histo[(df.histo.shift(1) < df.histo) & (df.histo.shift(-1) < df.histo)]
It does not add those two outputs into the same dataframe and throws the error mentioned in the question. However, if I want to save this into a new dataframe same code works, but that I don't want. I understand when updating same dataframe for local minima and maxima it should put "NaN" at all other locations but somehow the command is not working. Also i found a similar thread which shows the example (https://stackoverflow.com/a/48024165/13079994) for some random dataframe. Please help!