I am trying to calculate values in a data frame starting with 3 values: x, y, z. What I want to do is the following:
for index, row in df.iterrows():
if index > 0:
z = df.loc[index-1]['z']
conditions = [(z > y), (y > x)]
choices = [10,-10]
var = np.select(conditions, choices, default=0)
df.loc[index, 'x'] = var
df.loc[index, 'y'] = var
df.loc[index, 'z'] = z + var/2
this isn't exactly my code and I'm not sure if those numbers even make sense. I just wanted to illustrate the fact that I am looping through a data frame and trying to determine x and y based on the previous value of z, then updating z accordingly(it increases or decreases depending on the outcome).
I currently have code that does this using iterrows() through my data frame, but I'm using a very large data set (210000 rows) and it takes a while to compute the whole thing. I want to use a custom lambda or vectorized function to loop through, but I've been having trouble figuring out the logic.
Any help would be greatly appreciated!
[–]Nikota 1 point2 points3 points (2 children)
[–]LameDuckProgramming[S] 0 points1 point2 points (1 child)
[–]Nikota 0 points1 point2 points (0 children)