lundi 10 mai 2021

Using of for, If statements in padas dataframe to calculate duration

I am a newbie to pandas and python - Your answers are highly appreciated I have two columns in a data frame where it has values as follows: print(df)

|name        |date&time       
1 Start      2021-01-1 17:15:56 

2 Stop       2021-01-1 17:17:56 

3 Pause      2021-01-1 17:17:57 

4 Resume     2021-01-1 17:18:50

5 Progress   2021-01-1 17:19:58

6 Stop       2021-01-1 17:20:00

I am trying to get the duration of the total time spent here by excluding the time between pause and resume.

 If(name=='Start')
a=date&time of that name(start) (storing it in a temp variable)
 If(name=='Pause')
b=date&time of that name(Pause) (storing it in a temp variable)
c=a+b;
 If(name=='resume')
d=date&time of that name(resume) (storing it in a temp variable)
 If(name=='stop')
e=date&time of that name(Stop) (storing it in a temp variable)
f=d+e;
For(time=0)
time=time+(c+f)

thought of this pseudo code - Can anyone help me with this ?? Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire