更改系列中的值

Changing Values in a Series

我需要对一个系列进行一些调整。我有以下内容:

y.value_counts()

-1.0    775
 1.0    718
 0.0     32
Name: return_sign, dtype: int64

我想制作所有 0s = 1 并且我想要 -1 = 0

所以我最终会得到 750 (1s) 和 775 (-1s)。

我该怎么做?

试一试:

y = y.apply(lambda val : 1.0 if val >= 0 else 0)