我有一个数据框,如下所示:
fix = pd.DataFrame()
fix ['Home'] =['A','B','C','D','E']
fix ['Away'] =['F','G','H','I','J']
fix ['GD = -2'] = [0.2,0.3,0.5,0.1,0.6]
fix ['GD = -1'] = [0.25,0.1,0.55,0.35,0.43]
fix ['GD = 0'] = [0.1,0.2,0.23,0.5,0.4]
fix ['GD = 2'] = [0.1,0.5,0.2,0.12,0.18]
fix ['GD = 1'] = [0.24,0.5,0.33,0.31,0.13]
我想创建一个包含基于GD的获胜团队的新列(即GD + ve表示主场获胜,GD -Ve表示客队获胜,GD = 0表示平局。
所以我编写了以下代码来锻炼新列。
GDPlus = fix ['GD=1'] or fix['GD=2']
GDMins = fix ['GD= -1'] or fix['GD= -2']
fix['Winning_Team'] = np.select([GDPlus,GDMins],[fix.Home,fix.Away],default ='Draw')
它使我犯了如下错误:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
有人可以建议这样做吗?