Skip to content Skip to sidebar Skip to footer

Yield And Do Operations On Each 3 Rows Of DataFrame

I have this DataFrame, and would like to yield slices of 3 rows, returning a new DateFrame with all those 3 rows sets aggregated to one containing the highest date, the lowest open

Solution 1:

You can use groupby and aggregate

df.groupby(df.index//3).agg({'date': 'max', 'open': 'min', 'high': 'max', 'low': 'min','close': 'last'})

You get

    date        open        high        low         close
0   1498908300  0.00010010  0.00010020  0.00009957  0.00009957
1   1498909200  0.00009957  0.00010009  0.00009949  0.00009956

Post a Comment for "Yield And Do Operations On Each 3 Rows Of DataFrame"