0

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.

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 :

Takeoff,Landing Points

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!

Peter
  • 5
  • 6
  • Please add sample input and desired output as text in the question, not as pictures, to make a [mcve]. See [How to make good pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). It may also help to better describe how you are getting your takeoff and landing from the input data, the dexcription of the problem isn't clear – G. Anderson Feb 06 '20 at 17:30
  • Added extra info! – Peter Feb 06 '20 at 20:17

0 Answers0