Skip to content
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

[Docs] GroupsBy Example: Group by value of sum of columns #6288

Closed
mazieres opened this issue Feb 6, 2014 · 5 comments · Fixed by #6304
Closed

[Docs] GroupsBy Example: Group by value of sum of columns #6288

mazieres opened this issue Feb 6, 2014 · 5 comments · Fixed by #6304

Comments

@mazieres
Copy link
Contributor

mazieres commented Feb 6, 2014

Hi,
TomAugspurger suggested me on StackOverFlow to suggest this example of df.groupby() here for being considered as relevant to add to the docs. The idea was to determine a way to regroup columns of a DataFrame according to their sum, and to sum the aggregated ones.

In [1]: import pandas as pd

In [2]: dat = {'a':[1,0,0], 'b':[0,1,0], 'c':[1,0,0], 'd':[2,3,4]}

In [3]: df = pd.DataFrame(dat)

In [4]: df
Out[4]: 
   a  b  c  d
0  1  0  1  2
1  0  1  0  3
2  0  0  0  4

In [5]: df.groupby(df.sum(), axis=1).sum()
Out[5]: 
   1  9
0  2  2
1  1  3
2  0  4
@jreback
Copy link
Contributor

jreback commented Feb 6, 2014

sure....want to try to add in via a pull-request, see here: http://pandas.pydata.org/pandas-docs/dev/contributing.html

@jreback jreback added this to the 0.14.0 milestone Feb 6, 2014
@mazieres
Copy link
Contributor Author

mazieres commented Feb 6, 2014

Sure, i'll suggest a way to add it to the docs via PullRequest. Thanks.

@TomAugspurger
Copy link
Contributor

Great thanks. It should go under doc/source/groupby.rst.

@mazieres
Copy link
Contributor Author

mazieres commented Feb 7, 2014

OK, but The file you indicated misses most of the code snippet available at http://pandas.pydata.org/pandas-docs/dev/groupby.html, and I couldn't figure out where there are called from. Any hint ?

@jorisvandenbossche
Copy link
Member

I don't know exactly what you mean, but: (a) github does not render the rst files with code very well. So if you just look at https://github.com/pydata/pandas/blob/master/doc/source/groupby.rst you won't see the code snippets (but it you go to -> 'raw' or when you open it locally, you will see the code snippets) and (b) the code snippets in the docs only contain the code itself, and not the output as you see it on the html pages. This is because during the doc building all code snippets are run and the output generated and saved in the html (see explanation here: http://pandas.pydata.org/pandas-docs/stable/contributing.html#contributing-to-the-documentation)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants