0

I have used in the past a groupby operation as mentioned here to group a dataframe by every n rows. But, how can I preform an operation a dataframe that has a datetime index? When I try it on the following dataframe,

                                a           b           c
time                                                
2020-04-17 10:42:32.214624  538.401442  7260.312500 -713.166667
2020-04-17 10:42:33.086562  555.252404  7352.187500 -713.373264
2020-04-17 10:42:44.107187  572.103365  7444.062500 -713.579861
2020-04-17 10:42:44.648343  588.954327  7535.937500 -713.786458
2020-04-17 10:42:51.070750  605.805288  7627.812500 -713.993056
2020-04-17 10:42:53.567468  622.656250  7719.687500 -714.199653

I get the following error:

TypeError: cannot perform __truediv__ with this index type: DatetimeIndex

Is there a way that I can do a groupby, or some other operation to get groups of every 2 rows while keeping the datetime index?

Seth
  • 411
  • 2
  • 5
  • 13
  • 3
    Just add a new column with `np.arange(len(df))`? – roganjosh May 15 '20 at 16:56
  • 1
    This really is just a dupe of that question. You either add another column to use in `groupby` with floor division, or you instead work out a time period that you want to groupby. There's little room to deviate from the former in terms of it not being a dupe and, for the latter, not enough information to know how you'd want to group it in terms of time periods – roganjosh May 15 '20 at 17:00

0 Answers0