• 特征工程 python 批量生成变量名


    features = []

      diff_windowns = [1,3,6,12]
      groups = ['sum','mean','std','max','min','count']

    for d in diff_windowns:
        exec("""last_{}_month = df[df['diff_days']<={}].groupby('ACCOUNT')""".format(d,d))
        #last_3_month = df[df['diff_days']<=d].groupby('ACCOUNT')
        exec("""last_{}_month_gp = groupby_feature(last_{}_month)""".format(d,d))
        #features.append()
        for i,g in enumerate(groups):
            exec("""last_{}_month_{} = last_{}_month_gp[{}]""".format(d,g,d,i))
            #根据不同特征构造重命名列名
            exec("""last_{}_month_{}.columns = [c + '_last_{}_month_{}' for c in last_{}_month_{}.columns]""".format(d,g,d,g,d,g))
    #jupyter 里面查看生成的变量
    使用命令 %who_ls
    
    [...
    ...
    ...
     'last_12_month',
     'last_12_month_count',
     'last_12_month_gp',
     'last_12_month_max',
     'last_12_month_mean',
     'last_12_month_min',
     'last_12_month_std',
     'last_12_month_sum',
     'last_1_month',
     'last_1_month_count',
     'last_1_month_gp',
     'last_1_month_max',
     'last_1_month_mean',
     'last_1_month_min',
     'last_1_month_std',
     'last_1_month_sum',
     'last_3_month',
     'last_3_month_count',
     'last_3_month_gp',
     'last_3_month_max',
     'last_3_month_mean',
     'last_3_month_min',
     'last_3_month_std',
     'last_3_month_sum',
     'last_6_month',
     'last_6_month_count',
     'last_6_month_gp',
     'last_6_month_max',
     'last_6_month_mean',
     'last_6_month_min',
     'last_6_month_std',
     'last_6_month_sum',
    ....]
  • 相关阅读:
    Javascript事件处理进阶
    Restful API设计指南
    Git&GitHub
    Linux补充
    堡垒机
    Python发送邮件
    js获取当前页面url网址信息
    高并发的秒杀系统
    CMDB开发
    Tornado
  • 原文地址:https://www.cnblogs.com/cupleo/p/15670999.html
Copyright © 2020-2023  润新知