below small sample of dataframe : trying groupby.apply not giving me desired result.
in [204]: df1 out[204]: location_id terminal time 0 10000001405702 *whf 2016-07-01 13:56:00 1 10000001405702 @w1n 2016-07-01 09:14:39 2 10000001405702 *wu3 2016-07-01 11:54:52 3 10000001405702 @wjo 2016-07-01 11:30:57 4 10000001405702 @wcg 2016-07-01 11:06:24 5 10000001405702 *wl2 2016-07-01 10:04:20 6 10000001201132 a24o 2016-07-01 14:28:39 7 10000000564967 2jt1 2016-07-01 03:46:31 8 10000000615068 a125 2016-07-01 21:58:33 9 10000000552415 5mth 2016-07-01 05:51:39 10 10000001405702 *wqw 2016-07-01 00:09:06 11 10000000250413 ff41 2016-07-01 02:59:43 12 10000001125037 wq2i 2016-06-30 14:03:57 13 10000000174015 h5nm 2016-06-30 05:56:09 14 10000001856529 ar7k 2016-06-30 18:53:05
by doing below groupby.apply , losing location_id , terminal information , need .
in [206]: df1.groupby(['location_id','terminal'])['time'].apply(lambda x : x.diff()<=dt.timedelta(seconds=60)) out[206]: 0 false 1 false 2 false 3 false 4 false 5 false 6 false 7 false 8 false 9 false 10 false 11 false 12 false 13 false 14 false 15 false 16 false 17 false
i need output of below format such boolean info can known location_ids , terminal.
in [211]: df3 out[211]: time location_id terminal 10000000000081 3zr1 false cde1 true cde4 false gig2 true l43l false l43w false w9ye true yiw1 false yiw4 true zyi7 true zyjn false 10000000000086 a1e6 false a4dg true
still trying find grip in pandas. in advance.
the result of operation pandas series. if want column in dataframe need assign one.
make df3
copy of df1
, change call to:
df3['time'] = df1.groupby(['location_id','terminal'])['time'].apply(lambda x : x.diff()<=dt.timedelta(seconds=60))
also, apparently want 'location_id' , 'terminal' indexes of dataframe.
Comments
Post a Comment