I can't seem to figure out how to do this in one step. I want to set the even entries to 1 and the odd ones to -1:
df = DataFrame(np.arange(16).reshape(4,4))
x1 = df.where(df%2==0, -1)
x2 = x1.where(df%2!=0, 1)
The docs for pandas.DataFrame.where say:
Return an object of same shape as self and whose corresponding entries are from self where cond is True and otherwise are from other.
So is this the only way?