0

I try to get a player's playing time from the time he is in play according to the actual playing time.

I start learning python by trying to reproduce an R code I made. In R i use foverlaps this way :

Data <- foverlaps(Data_players, Data_play, type = "any")
Data[, `:=`(from = if_else( i.Start < Start, Start, i.Start),
               to = if_else( i.Stop > Stop, Stop, i.Stop) )][]
Data[, Time := as.numeric( to - from )]

Where Data_players and Data_play are composed of Start Time and End Time

In python I tried :

Data = pd.merge(Data_play, Data_player, on=['Start', 'Stop']) 

But it returns nothing in the data frame.

For exemple I have this Data_play :

Name        Start                           Stop
Play    1900-01-01 00:15:01.570000  1900-01-01 00:15:24.460000
Play        1900-01-01 00:15:56.240000  1900-01-01 00:16:04.330000

and this Data_player :

Name        Start                           Stop
Player      1900-01-01 00:14:58.500000      1900-01-01 00:16:25.600000

and expected new column 'Time' like this :

Name        Start        Stop        Time                                             
Player      ...          ...         00:00:30
P. Vauclin
  • 367
  • 1
  • 2
  • 10
  • Is `relativedelta` from `dateutil` what you are looking for ? https://dateutil.readthedocs.io/en/stable/relativedelta.html – Jona Mar 26 '19 at 16:51
  • @Jona I tried relativedelta but it will return me 1 minutes 27 seconds as it will do me Player['Stop'] - Player['Start'] or it is possible to return time that crosses the periods of Player with all Play ? – P. Vauclin Mar 26 '19 at 17:11
  • You might consider this answer : https://stackoverflow.com/questions/40247095/r-foverlaps-equivalent-in-python – Jona Mar 26 '19 at 19:49
  • Thanks @Jona but it seems it doesn't work in my case, instead I started creating a loop with ifs. I still have some improvements to make to take into account all cases but this is the solution I have found so far. – P. Vauclin Mar 28 '19 at 11:54

0 Answers0