Apr-03-2022, 01:34 PM
Link to question on StackOverflow
in the stackoverflow Yaloa_21 understood what i want to make but i always get errors
https://stackoverflow.com/questions/7157...5_71593640
Question about pandas
it's a little bit complicated , i have this dataframe :
i tried to do this but i'm afraid its not efficient because it shows the first and last one imagine if ID=13 has entered at 07:40:09 and the he check out at 08:40:09 , later that day he returns at 19:20:00 and leave in the next 10 minutes 19:30:00 if i do that fonction it will show that he worked for 12 hours
in the stackoverflow Yaloa_21 understood what i want to make but i always get errors
https://stackoverflow.com/questions/7157...5_71593640
Question about pandas
it's a little bit complicated , i have this dataframe :
ID TimeandDate Date Time 10 2020-08-07 07:40:09 2022-08-07 07:40:09 10 2020-08-07 08:50:00 2022-08-07 08:50:00 10 2020-08-07 12:40:09 2022-08-07 12:40:09 10 2020-08-08 07:40:09 2022-08-08 07:40:09 10 2020-08-08 17:40:09 2022-08-08 17:40:09 12 2020-08-07 08:03:09 2022-08-07 08:03:09 12 2020-08-07 10:40:09 2022-08-07 10:40:09 12 2020-08-07 14:40:09 2022-08-07 14:40:09 12 2020-08-07 16:40:09 2022-08-07 16:40:09 13 2020-08-07 09:22:45 2022-08-07 09:22:45 13 2020-08-07 17:57:06 2022-08-07 17:57:06i want to create new dataframe with 2 new columns the first one is df["Check-in"] , as you can see my data doesnt have any indicator to show what time the id has checked in , so i will suppose that the first time for every id is a check-in , and the next row is a check-out and will be inserted in df["Check-out"] , also if a check-in doesnt have a check-out time it has to be registred as the check-out for the previous check-out of the same day
i tried to do this but i'm afraid its not efficient because it shows the first and last one imagine if ID=13 has entered at 07:40:09 and the he check out at 08:40:09 , later that day he returns at 19:20:00 and leave in the next 10 minutes 19:30:00 if i do that fonction it will show that he worked for 12 hours
group = df.groupby(['ID', 'Date']) def TimeDifference(df): in = df['TimeandDate'].min() out = df['TimeandDate'].max() df2 = p.DataFrame([in-out], columns=['TimeDiff']) return df2 group.apply(TimeDifference)Desired Result
Output:ID Date Check-in Check-out
10 2020-08-07 07:40:09 12:40:09
10 2020-08-08 07:40:09 17:40:09
12 2020-08-07 08:03:09 10:40:09
12 2020-08-07 14:40:09 16:40:09
13 2020-08-07 09:22:45 17:57:06