1 回答

TA貢獻(xiàn)1911條經(jīng)驗(yàn) 獲得超7個(gè)贊
問(wèn)題是使用標(biāo)量,這里對(duì)于按位是必要的,也是必要的添加,因?yàn)閮?yōu)先級(jí)運(yùn)算符:and&AND()
conds = [(df['y'].values > mean + 3*st_dev), (df['y'].values < mean - 3*st_dev),
(df['y'].values <= (mean + 3*st_dev)) & ((mean - 3*st_dev) <= df['y'].values )]
choices = [1,0,2]
df['new'] = np.select(conds, choices)
print (df)
t y new
0 0 4 2
1 1 2 2
2 2 13 2
3 3 8 2
4 4 14 2
.. .. .. ...
95 95 5 2
96 96 10 2
97 97 8 2
98 98 6 2
99 99 16 2
[100 rows x 3 columns]
添加回答
舉報(bào)