Skip to content

API: way to exclude the grouped column with apply #7155

@jreback

Description

@jreback

http://stackoverflow.com/questions/23709811/best-way-to-sum-group-value-counts-in-pandas/23712433?noredirect=1#comment36441762_23712433
any of these look palatable?

df.groupby('c',as_index='exclude').apply(....)
df.groupby('c')['~c'].apply(...)
df.groupby('c',filter='c')
df.groupby('c',filter=True)

rather than doing a negated selection (df.columns-['c'])

df = pd.DataFrame.from_dict({'b1':['aa','ac','ac','ad'],\
                             'b2':['bb','bc','ad','cd'],\
                             'b3':['cc','cd','cc','ae'],\
                             'c' :['a','b','a','b']})

df.groupby('c')[df.columns - ['c']].apply(lambda x: x.unstack().value_counts())
Out[92]: 
c    
a  cc    2
   bb    1
   ad    1
   ac    1
   aa    1
b  cd    2
   ad    1
   ae    1
   ac    1
   bc    1
dtype: int64

Metadata

Metadata

Assignees

Labels

ApplyApply, Aggregate, Transform, MapDeprecateFunctionality to remove in pandasGroupby

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions