Continues Rolling Sum By Multiply Minutes Of Datetime In Python
I have this df dateTime 1min hour minute X EXPECTED Rolling_X 2017-09-19 02:00:04 2017-09-19 02:00:00 2 0 5 5 2017-09-19 02:00:04
Solution 1:
Okay, you need rolling now.
df = df.set_index('dateTime')
df['Roll_X'] = df.rolling('2T')['X'].sum()
df
Output:
1minhourminuteXEXPECTEDRolling_XRoll_XdateTime2017-09-19 02:00:04 2017-09-19 02:00:00 20555.02017-09-19 02:00:04 2017-09-19 02:00:00 20166.02017-09-19 02:00:04 2017-09-19 02:00:00 20177.02017-09-19 02:00:22 2017-09-19 02:00:00 20299.02017-09-19 02:01:31 2017-09-19 02:01:00 21099.02017-09-19 02:01:31 2017-09-19 02:01:00 2111010.02017-09-19 02:01:32 2017-09-19 02:01:00 2111111.02017-09-19 02:01:34 2017-09-19 02:01:00 2161717.02017-09-19 02:01:35 2017-09-19 02:01:00 2152222.02017-09-19 02:01:35 2017-09-19 02:01:00 2102222.02017-09-19 02:01:39 2017-09-19 02:01:00 2112323.02017-09-19 02:01:58 2017-09-19 02:01:00 2122525.02017-09-19 02:01:58 2017-09-19 02:01:00 2102525.02017-09-19 02:02:02 2017-09-19 02:02:00 2231928.02017-09-19 02:02:32 2017-09-19 02:02:00 2201919.02017-09-19 02:02:32 2017-09-19 02:02:00 2212020.02017-09-19 02:02:40 2017-09-19 02:02:00 22153535.02017-09-19 02:02:41 2017-09-19 02:02:00 2264141.02017-09-19 02:02:44 2017-09-19 02:02:00 2214242.02017-09-19 02:02:53 2017-09-19 02:02:00 2234545.02017-09-19 02:03:00 2017-09-19 02:03:00 2313046.02017-09-19 02:03:00 2017-09-19 02:03:00 2313147.02017-09-19 02:03:05 2017-09-19 02:03:00 2313248.02017-09-19 02:04:07 2017-09-19 02:04:00 2471036.02017-09-19 02:04:58 2017-09-19 02:04:00 2421212.02017-09-19 02:05:22 2017-09-19 02:05:00 25112320.02017-09-19 02:05:36 2017-09-19 02:05:00 2522522.0
Check around 2:03 where values differ. How did you calculate 30 when I got 46?
Post a Comment for "Continues Rolling Sum By Multiply Minutes Of Datetime In Python"