Imagine for the following DataSet:
data = {"row1":[1,2,3,4,5], "row2" : [2,3,4,1,3], "row3":[3,4,2,0,0] }
data = pd.DataFrame(data)
data = data.T
print(data)
0 1 2 3 4
row1 1 2 3 4 5
row2 2 3 4 1 3
row3 3 4 2 0 0
I want to find the min value
that appears after the max value
. So any min value that exists before the max value is not of my interest.
I have written this code:
data["Max_Value"] = data.max(axis=1)
data["Max_Index"] = data.idxmax(axis=1)
dt["Min_Value"] = dt.iloc[:, dt["Max_Index"]:].min(axis=1)
dt["Min_Index"] = dt.iloc[:, dt["Max_Index"]:].idxmin(axis=1)
dt["Max_Index"]:]
is my attempt to get the index of max value in a dynamic way. So then I can find the min value which appears after that part of the data set. But it doesn't work as I intend to.
I want to have an outcome as follow:
0 1 2 3 4 Max_Value Max_Index Min_Value Min_Index
row1 1 2 3 4 5 5 4 5 4
row2 2 3 4 1 3 4 2 1 3
row3 3 4 2 0 0 4 1 0 3
It doesn't work and I don't want to use the loop as well, what is my mistake?