案例1:

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())

案例2:

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','知友密度')

网友评论