【程序媛晒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

相关文章
|
11月前
510特辑 | 读懂阿里日,也就读懂了阿里
510特辑 | 读懂阿里日,也就读懂了阿里
204 0
|
8月前
|
安全 Python
让代码创造童话,共建快乐世界:六一儿童节特辑
让代码创造童话,共建快乐世界:六一儿童节特辑
|
存储 弹性计算 运维
介绍几本阿里人写的书
再过一周就是读书节,分享几本阿里人写的书,希望对大家选书、读书有一定的帮助。
1314 0
介绍几本阿里人写的书
|
SQL 分布式计算 前端开发
长路漫漫,其修远兮,这一年我与CSDN的故事 | 2021年终总结
长路漫漫,其修远兮,这一年我与CSDN的故事 | 2021年终总结
140 0
长路漫漫,其修远兮,这一年我与CSDN的故事 | 2021年终总结
|
机器学习/深度学习 Cloud Native 前端开发
阿里技术人和开发者朋友们的私藏书单
在快速变化、充满不确定的时代大背景下,拥抱变化成为常态。该如何应对、如何破局? 通过读书持续学习、持续精进,可能是其中成本最低、最高效的一种方式。
阿里技术人和开发者朋友们的私藏书单
|
人工智能 运维 开发者
【云栖精选】帮你把握“金三银四”,阿里开发者招聘节面经总结帖来袭
云栖精选,一文为你网罗本周云栖社区本周精华帖,精彩不容错过。换工作、找实习,那你一定不能错过“金三银四”,想要来阿里巴巴,一些笔试和面试技巧一定不能少。本期中,为大家选取了几篇关于阿里招聘节的相关内容。
7355 0
|
安全 大数据
一群阿里码农的公益实践:用技术禁毒、打拐
你愿意花多长时间去做公益?阿里安全的一群技术志愿者们分别给出了这样的回答:两年、上百个小时、7个月、每一年……正是这样的时间投入,全国首个线上儿童打拐平台“团圆”、向2亿青少年普及禁毒知识的“青骄第二课堂”先后在他们手中诞生。
4609 0