def transform(data,var): df[var + '_log'] = df[var].apply(np.log) transform(merged_inner,'Marks')
有两个错误,首先是标记是字符串,所以它应该在引号内,使用DF[var ]代替DF.var。