# 【Python数据清洗】for循环+条件判断 VS 数据向量化

df_2=grouped.copy()
df_2['serch']=np.where((df_2['laon_amt']>-0.01)&(df_2['laon_amt']<=5.5),1,\
np.where((df_2['laon_amt']>5.5)&(df_2['laon_amt']<=7.5),2,\
np.where((df_2['laon_amt']>7.5)&(df_2['laon_amt']<=8.5),3,\
np.where((df_2['laon_amt']>8.5)&(df_2['laon_amt']<=11.5),4,\
np.where((df_2['laon_amt']>11.5)&(df_2['laon_amt']<=13.5),5,\
np.where((df_2['laon_amt']>13.5)&(df_2['laon_amt']<16.5),6,\
np.where((df_2['laon_amt']>16.5)&(df_2['laon_amt']<=23.5),7,\
np.where((df_2['laon_amt']>23.5)&(df_2['laon_amt']<=30.5),8,\
np.where((df_2['laon_amt']>30.5)&(df_2['laon_amt']<=44.5),9,\
np.where((df_2['laon_amt']>44.5)&(df_2['laon_amt']<=359.01),10,0))))))))))



for i in range(df_2.shape[0]):
if (df_2['laon_amt'][i]>-0.01)&(df_2['laon_amt'][i]<=5.5):
df_2['serch'][i]=1
elif (df_2['laon_amt'][i]>5.5)&(df_2['laon_amt'][i]<=7.5):
df_2['serch'][i]=2
elif (df_2['laon_amt'][i]>7.5)&(df_2['laon_amt'][i]<=8.5):
df_2['serch'][i]=3
elif (df_2['laon_amt'][i]>8.5)&(df_2['laon_amt'][i]<=11.5):
df_2['serch'][i]=4
elif (df_2['laon_amt'][i]>11.5)&(df_2['laon_amt'][i]<=13.5):
df_2['serch'][i]=5
elif (df_2['laon_amt'][i]>13.5)&(df_2['laon_amt'][i]<165.5):
df_2['serch'][i]=6
elif (df_2['laon_amt'][i]>13.5)&(df_2['laon_amt'][i]<165.5):
df_2['serch'][i]=6
elif (df_2['laon_amt'][i]>13.5)&(df_2['laon_amt'][i]<165.5):
df_2['serch'][i]=6
elif(df_2['laon_amt'][i]>16.5)&(df_2['laon_amt'][i]<=23.5):
df_2['serch'][i]=7
elif (df_2['laon_amt'][i]>23.5)&(df_2['laon_amt'][i]<=30.5):
df_2['serch'][i]=8
elif (df_2['laon_amt'][i]>30.5)&(df_2['laon_amt'][i]<=44.5):
df_2['serch'][i]=9
elif (df_2['laon_amt'][i]>44.5)&(df_2['laon_amt'][i]<=359.01):
df_2['serch'][i]=10


-----------------------------分享结束线------------------------------

©️2019 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客