faraa
faraa

Reputation: 575

group by day of week and another column in pandas

I want to group by two columns. day of the week and another second column. but I don't know How should I do this. It is my query for one column:

grouped = (df.groupby(df['time'].dt.weekday_name)['id'].count().rename('count'))

Where should I add the second column? for example "type" column in my dataframe.

Upvotes: 1

Views: 399

Answers (1)

Nicolas Gervais
Nicolas Gervais

Reputation: 36594

df.groupby() takes a list, like this:

df.groupby([df['time'].dt.weekday_name, df['type']])

Upvotes: 1

Related Questions