fen
fen

Reputation: 91

Pandas groupy: retrieve columns on which data is grouped

Given a pandas GroupBy object, for example, set up like so

group = df.groupby([['col_1', 'col_2']])

Is there any way to return the column names on which that data has been grouped e.g.

group.get_grouped_columns()

which might return

['col_1', 'col_2']

Upvotes: 1

Views: 49

Answers (2)

user3483203
user3483203

Reputation: 51165

You need keys:

>>> group.keys
['col_1', 'col_2']

Upvotes: 2

BENY
BENY

Reputation: 323326

grouper with names

group.grouper.names
Out[96]: ['col_1', 'col_2']

Upvotes: 2

Related Questions