Skip to content

df.groupby('key').groups printed all: problem with large arrays #1135

Closed
@jorisvandenbossche

Description

@jorisvandenbossche

When you are working with a large array, it is not printed out in its entirety in the console, but when you have grouped them with groupby('key'), the groups are all printed out. Would it be possible to also restrict the output of groupby('key').groups to eg the first and last groups?

I was working with a rather large dataframe (around 80000 rows), and first it took a long time to print it all, and second the console got stuck for a while (but that could also be an issue with spyder).
I know it is not very useful to print out the groups, but I was curious to see what it would look like, but it was not a very good idea with such a large array.

>>> import numpy as np
>>> import pandas as pd
>>> df = pd.DataFrame(np.random.randn(100000, 4), columns=list('abcd'))
>>> df['g'] = np.random.randint(0, 100, 100000)
>>> df.groupby('g').groups  # this repr should be truncated

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions