I have a dataframe that looks like this :
ID time city transport
0 1 10:20:00 London car
1 20 08:50:20 Berlin air plane
2 44 21:10:00 Paris train
3 32 10:24:00 Rome car
4 56 08:53:10 Berlin air plane
5 90 21:8:00 Paris train
.
.
.
1009 446 10:21:24 London car
I want to group these data so that same value in 'city' and 'transport' but with time difference of +3min or -3min should have the same 'ID'.
I already tried pd.Grouper() like this but didn't work:
df['time'] = pd.to_datetime(df['time'])
df['ID'] = df.groupby([pd.Grouper(key= 'time',freq ='3min'),'city','transport'])['ID'].transform('first')
The output is the first dataframe I had without any changes. One reason could be that by using .datetime the date will be added as well to "time" and because my data is very big the date will differ and groupby doesn't work. I couldn't figure it out how to add time intervall (+3min or -3min) while using groupby and without adding DATE to 'time' column.
What I'm expecting is this :
ID time city transport
0 1 10:20:00 London car
1 20 08:50:20 Berlin air plane
2 44 21:10:00 Paris train
3 32 10:24:00 Rome car
4 20 08:53:10 Berlin air plane
5 44 21:8:00 Paris train
.
.
.
1009 1 10:21:24 London car
it has been a while that I'm struggling with this question and I really appreciate any help. Thanks in advance