Skip to content

DataFrame.groupby().groups should truncate output #2628

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

Closed
pikeas opened this issue Jan 2, 2013 · 3 comments
Closed

DataFrame.groupby().groups should truncate output #2628

pikeas opened this issue Jan 2, 2013 · 3 comments

Comments

@pikeas
Copy link

pikeas commented Jan 2, 2013

The output from .groups on a grouped DataFrame should be handled similarly to a large DataFrame, where beyond a certain length, the data is displayed in a summary form rather than output in its entirety.

This truncation should occur both at the group level (large number of groups) and per-group (large amount of data points in a group).

@cpcloud
Copy link
Member

cpcloud commented Feb 4, 2013

bump. What about the groups property being a DataFrame with nans filing unequal group sizes? I don't know about others, but I frequently find myself converting groups to a DataFrame.

@kokes
Copy link
Contributor

kokes commented Oct 3, 2018

Truncation on the per-group basis already works now, because indices in pandas have their own __repr__.

pd.DataFrame({'a': [random.randint(0, 100) for j in range(10000)]}).groupby('a').groups

As for the group-level truncation, that's a bit tricky, because the .groups property is a plain dictionary. What could be done is that we could create a class that inherits from dict and adds a custom __repr__ and nothing else. Something along these lines:

class DataFrameGroups(dict):
	def __repr__(self):
		if len(self) < 30:
			return super().__repr__()

		for k, v in self.items():
			pass # build representation here

@jreback
Copy link
Contributor

jreback commented Dec 19, 2018

closing as duplicate

@jreback jreback closed this as completed Dec 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants