-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Added additional example for groupby by indexer. #13276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -1014,6 +1014,13 @@ Regroup columns of a DataFrame according to their sum, and sum the aggregated on | |||
df | |||
df.groupby(df.sum(), axis=1).sum() | |||
|
|||
Groupby by Indexer to 'resample' data. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a fair bit more explanation of the why and how this does what it does. Maybe show the intent of a resample, then show how one can go about the same idea using non-datetimelike indices.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need a markdown line here like the other examples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you underline this with ~~~~
to make this a header (see a few lines above this for an example)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you forgot this one
Added more documentation and examples to clarify resampling as whole. |
|
||
In order to resample to work on indices that are non-datetimelike , the following procedure can be utilized. | ||
|
||
In the following examples, **df.index / 5** returns a binary array which is used to determine what get's selected for the groupby operation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can show this (add another ipython block), df.index / 5
|
||
In the following examples, **df.index / 5** returns a binary array which is used to determine what get's selected for the groupby operation. | ||
|
||
.. note:: The above example shows how we can downsample. Downsampling refers to the throwing away of samples. Here by using **df.index / 5**, we are throwing away half the samples. Here we also aggregate 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. Hence we can reduce the number of samples by creating bins by clubbing together samples. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't throw away samples at all. We aggregate them.
|
||
df = pd.DataFrame(np.random.randn(10,2)) | ||
df | ||
df.index / 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not work as desired in python 3. Can you make this df.index // 5
to do a floor division explicitly?
@pfrcks Added a few more comments. |
@jorisvandenbossche kindly go through the changes and comment. |
Current coverage is 84.33%@@ master #13276 diff @@
==========================================
Files 138 138
Lines 50581 51107 +526
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 42582 43103 +521
- Misses 7999 8004 +5
Partials 0 0
|
|
||
In the following examples, **df.index // 5** returns a binary array which is used to determine what get's selected for the groupby operation. | ||
|
||
.. note:: The below example shows how we can downsample which is the throwing away of 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't like the "throwing away of samples". You don't throw them away, IMO you process them in some way (eg taking the mean of each group of samples)
@jorisvandenbossche Sorry, I overlooked that. Have made the necessary changes. Please look and comment. |
@pfrcks Thanks! |
git diff upstream/master | flake8 --diff