美文网首页
python中*args函数的使用

python中*args函数的使用

作者: 一天天111 | 来源:发表于2019-10-20 10:49 被阅读0次

案例1:


image.png
def data_time(df,*cols):
    for col in cols:
        df[col] = df[col].str.replace('年','.')
        df[col] = df[col].str.replace('月','.')
        df[col] = df[col].str.replace('日','')
        df[col] = pd.to_datetime(df[col])
    return(df)
    
data_c2=data_time(data_c1,'数据获取日期')
print(data_c2.head())
image.png

案例2:


image.png
def data_norm(df,*cols):#*args函数的使用还是不太习惯哦
    
    for col in cols:
        colname= col + '_nor'
        df[colname]=(df['_id']-df['_id'].min())/(df['_id'].max()-df['_id'].min())*100
        
    return df  


result1=data_norm(q1data,'_id','知友密度')
image.png

相关文章

网友评论

      本文标题:python中*args函数的使用

      本文链接:https://www.haomeiwen.com/subject/anmvmctx.html