GroupBy.sum
N = 5s.groupby(s.index // N).sum()0 101 352 603 854 1105 1356 1607 1858 2109 235dtype: int64
将索引分为5组,并相应地分组。
numpy.reshape
+ sum
如果大小是N的倍数(或5),则可以调整形状并添加:
s.values.reshape(-1, N).sum(1)# array([ 10, 35, 60, 85, 110, 135, 160, 185, 210, 235])
numpy.add.at
b = np.zeros(len(s) // N)np.add.at(b, s.index // N, s.values)b# array([ 10., 35., 60., 85., 110., 135., 160., 185., 210., 235.])



