I have the data of players who play the ball, what I want is to record in the new columns the exact moment the ball leaves the ground and when it touches it, for this I have created two columns "take off" and "landing", in my initial dataset I have only Id, ground and timestamp. I have to register the process in all the players of the dataset.
Extra data:
When the ball is on the ground = True and this value changes for the first time to False is when I should extract that value and record it in the takeoff column replicating it while gorund = False therefore it should appear in all rows. The landing is the same but capturing the first value since ground = False changes to True.
All this process is seen in the dataset, I add image of the points to extract :
I have thought about it in the following way:
count = 0
ground_v = True
for row in df.iterrow():
if(ground_v != row["ground"]):
ground_v = False
if(count==0):
df["takeoff"]=row["timestamp"]
else:
df["touchdown"]=row["timestamp"]
elif((ground_v == False ) & (ground_v != row["ground"])):
ground_v = True
if(count == 0): #Im using the count because may be more than one takeoff value.
df["takeoff"]=row["timestamp"]
else:
df["touchdown"]=row["timestamp"]
I'm not sure if I can add value in Python that way.
The dataframe I added is how the values of the takeoff and landing columns should look like.
Thanks for your help!