I have a DataFrame like this one :
date open high low close vwap
0 1498907700 0.00010020 0.00010020 0.00009974 0.00010019 0.00009992
1 1498908000 0.00010010 0.00010010 0.00010010 0.00010010 0.00010010
2 1498908300 0.00010010 0.00010010 0.00009957 0.00009957 0.00009992
3 1498908600 0.00009957 0.00009957 0.00009957 0.00009957 0.00000000
4 1498908900 0.00010009 0.00010009 0.00009949 0.00009959 0.00009952
5 1498909200 0.00009987 0.00009991 0.00009956 0.00009956 0.00009974
6 1498909500 0.00009948 0.00009948 0.00009915 0.00009915 0.00009919
...
789
And would like to do a mean of each 3 rows and have a new DataFrame which is then 3 times shorter with the mean of all sets of 3 rows inside the source DataFrame.
The Syntax for Using Group By in SQLORDER BY column_name; The columns to be retrieved are specified in the SELECT statement and separated by commas. Any of the aggregate functions can be used on one or more than one of the columns being retrieved.
Pandas DataFrame aggregate() MethodThe aggregate() method allows you to apply a function or a list of function names to be executed along one of the axis of the DataFrame, default 0, which is the index (row) axis. Note: the agg() method is an alias of the aggregate() method.
Use groupby
and mean
with an array designed to form the groups you need
df.groupby(np.arange(len(df)) // 3).mean()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With