This is most likely something very basic, but I cannot understand it. Suppose I have a series like this:
s1 = pd.Series([1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4])
How can I perform operations on the sub-series of this series without returning to using the for loop?
Suppose, for example, that I want to turn it into a new series containing four elements. The first element of this new series is the sum of the first three elements in the original series (1, 1, 1), the second is the sum of the second three (2, 2, 2), etc .:
s2 = pd.Series([3, 6, 9, 12])
How can i do this?
source share