How can I loop the dataframe and perform some conditions without using for loop for df(cuz it's slow) without converting to array or list and without using the itertuples, nor iterrows functions? Because I heard make use of pandas vectors is faster.
df =
Idx Var1 Var2 Var3
0 0 3 0
1 10 0 0
2 0 0 2
3 0 3 0
4 0 0 1
5 10 0 2
6 0 1 1
7 0 0 0
8 0 3 0
For example:
- Start logging when Var1 > Var3
- Once logging is started, if Var2 < Var3, start over from condition 1 again.
- Else, Keep scanning until (Var2 > Var3) is found
- If Var2 > Var3, mark it down
- Do this process through the whole dataframe
- Return df(all rows) with conditions met
So basically it should return only 8 0 3 0 in this example. 0 0 3 0 is not it because condition 1 hadn't started yet. 3 0 3 0 is not it because 2 0 0 2 violated the condition 2, so it has to start from condition 1 again. Thanks
Aucun commentaire:
Enregistrer un commentaire