【发布时间】:2020-06-15 17:17:54
【问题描述】:
我想将WinorLoss 列中的所有数据从 W/L 替换为 1/0(如果 W,则为 1,如果 L,则为 0)..
WinorLoss 是我的 csv 文件中的一列,其中填充了对应游戏的 W 或 L
我尝试了以下方法:
if df.WinorLoss == "W":
df.WinorLoss == "1"
else:
df.WinorLoss == "0"
出现以下错误:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
我是 python 新手,所以不是 100% 如何去做这件事.. 任何帮助将不胜感激?
【问题讨论】:
-
df['WinorLoss'].map({'W': 1, 'L': 0})或numpy.where:np.where(df['WinorLoss'] == 'W', 1, 0)
标签: python pandas if-statement jupyter