Pandas groupby TypeError: '>' not supported between instances of 'SeriesGroupBy' and 'int'

Viewed 2769

I have the following code:

group = df.groupby(['Id',  'Name'])
conditions = [
    ((group["Balance"]>0) & (group['Value']>0) & (group['L_Date']<=group['c_date'])),
    ((group["Balance"]==0) & (group['Value']==0) & (group['L_Date']<=group['c_date']))]
choices = ['Good', 'Bad']
df['outcome'] = np.select(conditions, choices, default='Normal')

But it is giving me the following error:

TypeError: '>' not supported between instances of 'SeriesGroupBy' and 'int'

What is the correct way to do this?

1 Answers

I think there is no reason use groupby, because in code are not count some values per groups.

group = df.groupby(['Id',  'Name'])

Use only:

conditions = [
    ((df["Balance"]>0) & (df['Value']>0) & (df['L_Date']<=df['c_date'])),
    ((df["Balance"]==0) & (df['Value']==0) & (df['L_Date']<=df['c_date']))]
choices = ['Good', 'Bad']
df['outcome'] = np.select(conditions, choices, default='Normal')
Related