【发布时间】:2019-02-14 13:05:57
【问题描述】:
我有一个如下的数据框:
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().
谁能告诉我该怎么做?
【问题讨论】:
-
在 pandas 中按位
OR使用|,但它用于链接布尔掩码。 -
预期输出是什么?
-
这些是赔率吗?赔率最高的列应该是结果?
标签: python pandas dataframe conditional-operator