dimanche 7 février 2021

Creating conditions to replace missing values in pandas that include Strings, Date and Time

In my df I am trying to replace values in column 'Amount in (L)' based on the date and time and the Milking events that occurred that day.

  Milk Event          Date        Time     Amount in (L)
       Start    04/08/2001       09:00               nan 
         End    04/08/2001       10:00              1500   
       Start    04/08/2001       14:00               nan 
         End    04/08/2001       15:00              2000   
       Start    05/08/2001       08:00               nan 

I am unsure whether to use a for loop or if statement to create conditions that replace the nan with the previous 'End' events amount. I would want it to look something like:

   Milk Event          Date        Time     Amount in (L)
       Start    04/08/2001       09:00                 0 
         End    04/08/2001       10:00              1500   
       Start    04/08/2001       14:00              1500 
         End    04/08/2001       15:00              2000   
       Start    05/08/2001       08:00              2000

Aucun commentaire:

Enregistrer un commentaire