Skip to content

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

Merged
merged 7 commits into from
Jun 28, 2016

Conversation

pfrcks
Copy link
Contributor

@pfrcks pfrcks commented May 25, 2016

@jreback jreback added the Docs label May 25, 2016
@@ -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.
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Member

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)

Copy link
Member

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

@pfrcks
Copy link
Contributor Author

pfrcks commented May 25, 2016

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.
Copy link
Contributor

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.
Copy link
Contributor

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
Copy link
Member

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?

@jorisvandenbossche
Copy link
Member

@pfrcks Added a few more comments.

@pfrcks
Copy link
Contributor Author

pfrcks commented Jun 27, 2016

@jorisvandenbossche kindly go through the changes and comment.

@codecov-io
Copy link

codecov-io commented Jun 27, 2016

Current coverage is 84.33%

Merging #13276 into master will increase coverage by 0.15%

@@             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          

Powered by Codecov. Last updated by e0a2e3b...39b7fac


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.
Copy link
Member

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)

@pfrcks
Copy link
Contributor Author

pfrcks commented Jun 28, 2016

@jorisvandenbossche Sorry, I overlooked that. Have made the necessary changes. Please look and comment.

@jorisvandenbossche jorisvandenbossche merged commit 9e73c71 into pandas-dev:master Jun 28, 2016
@jorisvandenbossche
Copy link
Member

@pfrcks Thanks!

@jorisvandenbossche jorisvandenbossche added this to the 0.18.2 milestone Jun 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DOC: groupby by indexer to 'resample' data
4 participants