trying to compare EVERY value within the row of one dataframe against EVERY other value
based on if decision in row that relates to the row before
> If value1 > value2: # in row_x
> based_on_previous_value(value1)
referring to row_x-1 to then trying to build a new dataframe with these values df_new
example)
df = pandas.DataFrame({"R1": [8,2], "R2": [-21,-24], "R3": [-9,46]})
# second row in df_new for (just a simple example of a function for clarification reasons)
def based_on_previous_value(x):
return x*2
df_new = pandas.DataFrame({"R1": [32,2], "R2": [-21,-24], "R3": [-18,46]})
> # 8 --> 32 (because 8 ist bigger than -21 & 8 is bigger than -9) --> 8*2*2 = 32
> # -21 --> -21 (because -21 is smaller than 8 & smaller than -9) --> -21 = -21
> # -9 --> -18 (because -9 is smaller than 8 & bigger than -21) --> -9*2 = 18
EDIT: example2)
# I have a dataframe that Looks like this:
df = pandas.DataFrame({"R1": [8,2,3], "R2": [-21,-24,4], "R3": [-9,46,6],"R4": [16,-14,-1],"R5": [-3,36,76]})
as above: I want to compare every value within one row against each other, to then apply a function (if value 1 in row x is bigger then value 2 in row x) i am trying to apply something like this:
If value1 in row1 > value2 in row 1:
based_on_previous_value(value1) # trying to put results in a new dataframe
Else:
return value1 # trying to put results in a new dataframe
def based_on_previous_value(x):
x in row_before + 1
--> this Code doesn't work (just trying to Show what I am trying to do in Code)
# results put in a new dataframe
df_new = pandas.DataFrame({"R1": [8,10,11], "R2": [-21,-21,-19], "R3": [-9,-5,-2],"R4": [16,17,17],"R5": [-3,0,4]})
--> "R1" in 2nd row: 2 > -24, 2 > -14 --> value("R1" in first row) + 2 = 10 --> "R2" in 2nd row: -21 < all the other 4 values --> value("R2" in first row) + 0 = -21 --> "R3" in 2nd row: 46 > all the other 4 values --> value("R3" in first row) + 4 = -5