Skip to content

Commit 9e73c71

Browse files
pfrcksjorisvandenbossche
authored andcommitted
DOC: Added additional example for groupby by indexer. (pandas-dev#13276)
1 parent 1a9abc4 commit 9e73c71

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

doc/source/groupby.rst

+17
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,23 @@ Regroup columns of a DataFrame according to their sum, and sum the aggregated on
10151015
df
10161016
df.groupby(df.sum(), axis=1).sum()
10171017
1018+
Groupby by Indexer to 'resample' data
1019+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1020+
1021+
Resampling produces new hypothetical samples(resamples) from already existing observed data or from a model that generates data. These new samples are similar to the pre-existing samples.
1022+
1023+
In order to resample to work on indices that are non-datetimelike , the following procedure can be utilized.
1024+
1025+
In the following examples, **df.index // 5** returns a binary array which is used to determine what get's selected for the groupby operation.
1026+
1027+
.. note:: The below example shows how we can downsample by consolidation of samples into fewer samples. Here by using **df.index // 5**, we are aggregating the samples in bins. By applying **std()** function, we aggregate the information contained in many samples into a small subset of values which is their standard deviation thereby reducing the number of samples.
1028+
1029+
.. ipython:: python
1030+
1031+
df = pd.DataFrame(np.random.randn(10,2))
1032+
df
1033+
df.index // 5
1034+
df.groupby(df.index // 5).std()
10181035
10191036
Returning a Series to propagate names
10201037
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)