Jatin Kapoor
Jatin Kapoor

Reputation: 39

Grouping multiple groups by group by pandas with multiple values in python

I have a file and in one column 'Saracen ID' has multiple values and i want group basis those values like 1. ('07111',07112') should come under one group. 2. (09084) come under second group 3. Rest if any in future will fall under third group.

I am trying to group multiple grouping through groupby and get_group

group_1=df.groupby('Saracen ID').get_group('07111',07112')
group_2=df.groupby('Saracen ID')get_group('09084')
group_1
group_2

I am getting the error 'str' object has not attribute 'take'

How to get multiple groups under one grouping in pandas.

Upvotes: 1

Views: 414

Answers (1)

BENY
BENY

Reputation: 323386

The way we filter the group is loc + isin

group_1 = df.loc[df['Saracen ID'].isin(['07111', '07112'])]

Upvotes: 1

Related Questions