普通打标签 odue_df = df_train_stmt . loc [( df_train_stmt . AGE3 0 ) | ( df_train_stmt . AGE4 0 ) | ( df_train_stmt . AGE5 0 ) | ( df_train_stmt . AGE6 0 ),[ 'XACCOUNT' ]]. drop_duplicates () odue_df [ 'label' ] = 1 cust_df = df_acct [
普通打标签
odue_df=df_train_stmt.loc[(df_train_stmt.AGE3>0)|(df_train_stmt.AGE4>0)|(df_train_stmt.AGE5>0)|(df_train_stmt.AGE6>0),['XACCOUNT']].drop_duplicates()odue_df['label']=1
cust_df=df_acct[['CUSTR_NBR','XACCOUNT']].drop_duplicates()
#做合并
df_y=pd.merge(cust_df,odue_df,how='left',on='XACCOUNT').groupby('CUSTR_NBR').agg({'label':max}).reset_index().fillna(0)
使用函数来打标签
#标注标签 Labeldef label(row):
if row['Date_received'] == 'null':
return -1
if row['Date'] != 'null':
td = pd.to_datetime(row['Date'], format='%Y%m%d') - pd.to_datetime(row['Date_received'], format='%Y%m%d')
if td <= pd.Timedelta(15, 'D'):
return 1
return 0
dfoff['label'] = dfoff.apply(label, axis=1)
#打标签,判断天数
def get_label(s):
s = s.split(':')
if s[0]=='null':
return 0
elif (date(int(s[0][0:4]),int(s[0][4:6]),int(s[0][6:8]))-date(int(s[1][0:4]),int(s[1][4:6]),int(s[1][6:8]))).days<=15:
return 1
else:
return -1
dataset2.label = dataset2.label.apply(get_label)