Add HTML repr for groupby dataframe and series
State: closed

After I saw the representation of a group by in Airtable, I wanted something similar in pandas. It always bothered me that there was no representation for a group by.

Update: 25.07.2020:
These are old screenshots, but still resemble the look. A new addition is the limitation of groups displayed. I don't know how to make the displaying width across all groups the same. If anyone has an idea, I'd appreciate it.

Update: 26.07.2020:
I've added three tests:

1. All rows in groups and all groups are shown
2. All groups are shown, but not all rows in groups.
3. All rows in groups are shown, but no all groups.

I unsure if it wise to put all cases into one test with an if statement which checks which of the above cases it is. Feedback welcome.

**DataFrame**:
![Screenshot from 2020-06-22 03-13-44](https://user-images.githubusercontent.com/31596773/85239940-75742100-b436-11ea-8b6a-99670d93591a.png)

**Series**:
![Screenshot from 2020-06-22 03-14-46](https://user-images.githubusercontent.com/31596773/85239970-8fadff00-b436-11ea-8f9e-b103c1a3ec2b.png)

This is a WIP implementation. Open issues are:
- [x] improve variable names
- [x] produce more clean HTML code
- [x] limit number of maximum group by DataFrames displayed (similar to the row limit)
- [x] improve look (Did not improve it, but I'm with it)
- [ ] Same width across all groups


- [ ] closes #xxxx
- [x] tests added / passed
- [x] passes `black pandas`
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry


Truncated groups with a maximum of 3 groups:
![Screenshot from 2020-09-05 16-17-33](https://user-images.githubusercontent.com/31596773/92306995-79becd80-ef93-11ea-86ca-d042ff2116b9.png)


Labels:
name: Groupby
name: Output-Formatting
description: __repr__ of pandas objects, to_string
name: IO HTML
description: read_html, to_html, Styler.apply, Styler.applymap
name: Stale

Comments:
@JulianWgs Are you still working on this?
Is this something of interest? 

1) I'm not sure if the added complexity of the code is worth the cleaner html.
2) Also I would need some help on how to improve the visual quality (design hints not necessarly technical help). The only thing I can think of is to set the column width equally across all tables.
I would suggest that if you were expecting feedback on the code, that you mark the PR as ready for review. Alternatively, if you want feedback on the idea, that you first open a feature request issue (and fill out the template)  
Hello @JulianWgs! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:









There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers: 

##### Comment last updated at 2021-07-04 09:10:36 UTC
@simonjayhawkins How do I fix the "ImportError: lxml not found, please install it" error in Travis CI ([Link](https://travis-ci.org/github/pandas-dev/pandas/jobs/711891902#L1318))?
@simonjayhawkins 
@simonjayhawkins 
sorry. will look soon. in the meantime merging upstream/master to resolve conflicts may help
The problem was that the [lxml](https://lxml.de/) dependency was missing. I've added `@td.skip_if_no("lxml")` to skip the test if it is missing. This is also done [here](https://github.com/pandas-dev/pandas/blob/497ede8065e81065636908fecd31432a91c1ff64/pandas/tests/io/test_html.py#L79).

Please review the PR :)
can you show what this does for a truncated repr? e.g. > 10 groups.
> can you show what this does for a truncated repr? e.g. > 10 groups.

I've updated the original pull request text accordingly
Is there a DataFrameGroupBy type?
> Is there a DataFrameGroupBy type?

yes that's the class where you did the change (or you may have done it in the super class)
@jreback: Any thoughts on whether tests for `groupby._repr_html_` should be in groupby tests or `io.formats.test_to_html` (or somewhere else)?
This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this.
@JulianWgs can you resolve conflicts (and move release note to 1.4)
@simonjayhawkins Done :)
this is quite old, happen to reopen if actively worked on.