df.were(),df.mask()

df.where(cond,other...) df.mask()

df.where将series中不满足cond的那些值替换为other

df.mask()结果与where()相反

In [45]:
 df['loan_amnt'].head(10).where(df['loan_amnt']<5000,5000)
 
 
Out[45]:
0    5000
1    2500
2    2400
3    5000
4    3000
5    5000
6    5000
7    3000
8    5000
9    5000
Name: loan_amnt, dtype: int64
In [46]:
 df['loan_amnt'].head(10).mask(df['loan_amnt']<5000,5000)
 
 
Out[46]:
0     5000
1     5000
2     5000
3    10000
4     5000
5     5000
6     7000
7     5000
8     5600
9     5375
Name: loan_amnt, dtype: int64

posted on 2019-08-19 08:22  离云1  阅读(587)  评论(0编辑  收藏  举报

导航