【程序媛晒83行代码】云栖社区聚能聊专家,背后83行代码的故事


在中国程序媛中,他们的代码有什么样的魅力,Aone联合云栖社区、饿了么、钉钉、阿里云、天猫、口碑发起首届程序媛比码活动——不秀大长腿,秀高智商;不秀美图照,秀代码图,参与晒码互动游戏赢“83行代码”T恤!

我们来说说这群女工程师的第83行代码及代码背后的故事:

平时习惯于用Jupyter Notebook写代码,以至于很多代码像是这样:


# 分块计算缺失程度(23块)
block_list = [1,5,6,20,24,28,32,36,48,52,54,64,72,76,102,107,111,155,161,166,211,254,278,298]

for i in tqdm(range(len(block_list)-1)):
    tmp_df = train_test.iloc[:,block_list[i]-1:block_list[i+1]-1]
    print(tmp_df.columns)
    tmp_df_T = tmp_df.T
    tmp_df['count'] = tmp_df_T.count()
    train_test['count_f' + str(block_list[i]) + '_f' +str(block_list[i+1])] = tmp_df['count']
    train_test['count_label_f' + str(block_list[i]) + '_f' +str(block_list[i+1]-1)]=np.where(train_test['count_f' + str(block_list[i]) + '_f' +str(block_list[i+1])] > 0,0,1)

# 计算占比(基于date)
for i in tqdm(r_list):
    df_dratio = pd.DataFrame()
    for j in date_list:
        df_tmp = train_test[train_test['date'] == j]
        f_ratio = pd.DataFrame(df_tmp[i].value_counts())
        f_ratio['date'] = j
        f_ratio[i + '_rcount'] = f_ratio[i]
        f_ratio[i + '_ratio'] = f_ratio[i]/len(df_tmp)
        f_ratio[i] = f_ratio.index
        f_ratio = f_ratio.reset_index(drop = True)
        df_dratio = pd.concat([df_dratio, f_ratio], axis = 0)
        df_dratio = df_dratio.reset_index(drop = True)
    train_test = train_test.merge(df_dratio,on = ['date',i],how = 'left')

比较喜欢的一段代码是这样:


import copy
def cal_all_altcol_1(col_, labelcol = None, error_corr = False):  
    
#     if labelcol is not None:
#         print("pcsing by groups")
        
    col = copy.deepcopy(col_)
    colname = col.columns[0]

    if(error_corr == True):
        if labelcol is not None:
            mean = pd.DataFrame(calmean(col, labelcol))
            alt_col = [col, 1 / col, col-mean, np.fabs(col-mean)]
            alt_col_name = [colname + "_X", colname + "_1/X", colname + "_Xerr", colname + "_Xerr_abs"]
        else:
            mean = calmean(col, labelcol)
            alt_col = [col, 1 / col, np.fabs(col-mean)]
            alt_col_name = [colname + "_X", colname + "_1/X", colname + "_Xerr_abs"]
    elif(error_corr == False):
        alt_col = [col , 1 / col]
        alt_col_name = [colname + "_X", colname + "_1/X"]
    
    alt_list = pd.concat(alt_col, axis = 1)
    alt_list.columns = alt_col_name
    return alt_list

def cal_all_altcol_1_base(col_, labelcol = None, error_corr = False):  
    # 只取正负列
    
#     if labelcol is not None:
#         print("pcsing by groups")
        
    col = copy.deepcopy(col_)
    colname = col.columns[0]
    
    if(error_corr == True):
        if labelcol is not None:
            mean = pd.DataFrame(calmean(col, labelcol))
            alt_col = [col, np.fabs(col-mean), col-mean, ]
            alt_col_name = [colname + "_X", colname + "_Xerr_abs", colname + "_Xerr"]
        else:
            mean = pd.DataFrame(calmean(col, labelcol))
            print(mean)
            alt_col = [col, np.fabs(col-mean)]
            alt_col_name = [colname + "_X", colname + "_Xerr_abs"]
    elif(error_corr == False):
        alt_col = [col]
        alt_col_name = [colname + "_X"]
    
    alt_list = pd.concat(alt_col, axis = 1)
#     print (alt_list)
    alt_list.columns = alt_col_name
    return alt_list


def cal_all_altcol_2(col_i, col_j, labelcol = None, error_corr = False):
    
#     if labelcol is not None:
#         print("pcsing by groups")
    coli = copy.deepcopy(col_i)
    colj = copy.deepcopy(col_j)
    coliname = coli.columns[0]
    coljname = colj.columns[0]
    colbet = coliname + "_" + coljname
    coli.columns, colj.columns = [colbet], [colbet] # 需要把列名统一不然不能直接减
    
    Plus = coli + colj
    Minus = coli - colj
    Multiply = coli * colj
    Divide_1 = coli / colj
    Divide_2 = colj / coli
    everynum_perpart = 5
    
    if(error_corr == True):
        P_mean = pd.DataFrame(calmean(Plus, labelcol))
        Mi_mean = pd.DataFrame(calmean(Minus, labelcol))
        Mu_mean = pd.DataFrame(calmean(Multiply, labelcol))
        D1_mean = pd.DataFrame(calmean(Divide_1, labelcol))
        D2_mean = pd.DataFrame(calmean(Divide_2, labelcol))
        if labelcol is not None:
            alt_col =  [Plus, Minus, Multiply, Divide_1, Divide_2,
                        np.fabs(Plus - P_mean), np.fabs(Minus - Mi_mean), np.fabs(Multiply - Mu_mean),
                        np.fabs(Divide_1 - D1_mean), np.fabs(Divide_2 - D2_mean),
                        Plus - P_mean, Minus - Mi_mean, Multiply - Mu_mean,Divide_1 - D1_mean, Divide_2 - D2_mean]
            alt_col_name = [colbet + "_X+Y", colbet + "_X-Y", colbet + "_X*Y", colbet + "_X/Y", colbet + "_Y/X",
                            colbet + "_X+Yerr_abs", colbet + "_X-Yerr_abs", colbet + "_X*Yerr_abs",
                            colbet + "_X/Yerr_abs", colbet + "_Y/Xerr_abs",
                            colbet + "_X+Yerr", colbet + "_X-Yerr", colbet + "_X*Yerr",
                            colbet + "_X/Yerr", colbet + "_Y/Xerr",]
        elif labelcol is None:
            alt_col = [Plus, Minus, Multiply, Divide_1, Divide_2, 
                       np.fabs(Plus - P_mean), np.fabs(Minus - Mi_mean), np.fabs(Multiply - Mu_mean),
                       np.fabs(Divide_1 - D1_mean), np.fabs(Divide_2 - D2_mean)]
            alt_col_name = [colbet + "_X+Y", colbet + "_X-Y", colbet + "_X*Y", colbet + "_X/Y", colbet + "_Y/X",
                            colbet + "_X+Yerr_abs", colbet + "_X-Yerr_abs", colbet + "_X*Yerr_abs",
                            colbet + "_X/Yerr_abs", colbet + "_Y/Xerr_abs"]
    elif(error_corr == False):
        alt_col = [Plus, Minus, Multiply, Divide_1, Divide_2]
        alt_col_name = [colbet + "_X+Y", colbet + "_X-Y", colbet + "_X*Y", colbet + "_X/Y", colbet + "_Y/X"]
    
    alt_list = pd.concat(alt_col, axis = 1)
    alt_list.columns = alt_col_name
#     print(alt_list)
    return alt_list
# def cal_all_alt2tol(coli, colj, )
# cal_all_altcol_2(test, test2)

与海洋的云小姐姐互动,为她打call——>点击进去晒码


更多小姐姐,点击进入查看代码

有被代码耽误的钉钉吃货程序媛,写代码写到忘记吃饭的——采霜
她急需能把她从代码中叫醒去吃饭的小伙伴,赶紧勾搭;
http://yq.aliyun.com/roundtable/126499/answer/170319#visit170319


有以代码为乐的饿了么大前端打(bei)杂(guo)工程师——敖天羽
http://yq.aliyun.com/roundtable/126499/answer/170299#visit170299


还有全栈美女工程师——前端后端一锅端的——墨瑜女神
http://yq.aliyun.com/roundtable/126499/answer/170316#visit170316


还有阿里云活好码赞,像男人一样活着的技术专家小姐姐——清宵http://yq.aliyun.com/roundtable/126499/answer/170296#visit170296


和天猫Java程序媛,happy(被)来(逼)的——采月
http://yq.aliyun.com/roundtable/126499/answer/170354#visit170354


阿里口碑 搜索推荐组的JAVA女工程师——妍霏
http://yq.aliyun.com/roundtable/126499/answer/214059#visit214059


阿里口碑基础平台技术部的工程师-衔远,一个技术与马甲线并存的mm
http://yq.aliyun.com/roundtable/126499/answer/248798#visit248798

云栖社区聚能聊专家,具有知性温婉气质的——海洋的云http://yq.aliyun.com/roundtable/126499/answer/170290#visit170290

福州市五佰网络科技有限公司的Java女工程师——江小白太白
http://yq.aliyun.com/roundtable/126499/answer/189332#visit189332


在下*的程序媛——cn_suqingnian
http://yq.aliyun.com/roundtable/126499/answer/170309#visit170309


交通银行的前端女工程师——昆0830
http://yq.aliyun.com/roundtable/126499/answer/201979#visit201979

上一篇:【程序媛晒83行代码】Java女工程师江小白,偷偷亮代码被老板发现


下一篇:【程序媛晒83行代码】阿里口碑平台技术部工程师,不秀美颜秀代码