我有以下代码:
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'
正确的方法是什么?
我认为没有理由使用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')
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句