我有以下代码:
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')
但这给了我以下错误:
TypeError: '>' not supported between instances of 'SeriesGroupBy' and 'int'
正确的方法是什么?
答案 0 :(得分:3)
我认为没有理由使用groupby
,因为在代码中没有按组计算某些值。
group = df.groupby(['Id', 'Name'])
仅用于:
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')