I have been searching for a way to replace itterrows with vectorization and coming up blank. I have this code which i believe to be working correctly using itterows which is taking forever.
sm_state = 0
fst_state = 0
time = 0
for index, row in df.iterrows():
if row['Current'] < -5 or row['Current'] > 5 or row[active] == 0:
sm_state = 0
fst_state = 0
time = 0
else:
sm_state = 1
fst_state = 1
time = row['ElapsedTime']
if row['ElapsedTime'] - time >= smooth_time and sm_state == 1:
sm_state = 2
if row['ElapsedTime'] - time >= fast_time and fst_state == 1:
fst_state = 2
df.loc[index,'sm_timing'] = sm_state
df.loc[index,'fst_timing'] = fst_state
return df
In summary what this is doing is when current is ~0 and active = 1 it stores the elapsedtime at that point (first time it is true) and new column should be a 1. Then if those conditions remain true for a "time" the value in the new column changes to a 2. if current goes outside of 0 the new column should return to a 0 and begin looking for current == 0 and active == 1 again.
any help or advice is greatly appreciated.