I have a fairly simple question based on this sample code:
x1 = 10*np.random.randn(10,3)
df1 = pd.DataFrame(x1)
I am looking for a single DataFrame derived from df1
where positive values are replaced with "up"
, negative values are replaced with "down"
, and 0
values, if any, are replaced with "zero"
. I have tried using the .where()
and .mask()
methods but could not obtain the desired result.
I have seen other posts which filter according to multiple conditions at once, but they do not show how to replace values according to different conditions.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…