最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
python实现添加标签&打标签操作代码
时间:2022-06-25 02:00:18 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下python实现添加标签&打标签操作代码,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
普通打标签
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)
使用函数来打标签
#标注标签 Label
def 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)
相关文章
- 九牧之野太史慈连弓队如何搭配 12-18
- 《LOFTER》隐藏破次元信号入口技巧 12-18
- 王者万象棋阿科米亚核心是什么 12-18
- SkrBT磁力官网最新入口-skrbt磁力引擎新版入口 12-18
- 空灵诗篇遗物有哪些获取途径 12-18
- 学科网官网登录入口高中版-中学历史学科网官方登录入口 12-18