python_折扣优惠数据处理 #提取优惠券的相关特征 def calc_discount_rate ( s ): s = str ( s ) s = s . split ( ':' ) if len ( s ) == 1 : return float ( s [ 0 ]) else : return 1.0 - float ( s [ 1 ]) / float ( s [ 0 ]) def get_di
python_折扣优惠数据处理
#提取优惠券的相关特征def calc_discount_rate(s):
s = str(s)
s = s.split(':')
if len(s) == 1:
return float(s[0])
else:
return 1.0-float(s[1])/float(s[0])
def get_discount_man(s):
s = str(s)
s = s.split(':')
if len(s)==1:
return 'null'
else:
return int(s[0])
def get_discount_jian(s):
s = str(s)
s = s.split(':')
if len(s) == 1:
return 'null'
else:
return int(s[1])
def is_man_jian(s):
s = str(s)
s = s.split(':')
if len(s)==1:
return 0
else:
return 1
#显示满了多少钱后开始减
dataset3['discount_man'] = dataset3.discount_rate.apply(get_discount_man)
#显示满减的减少的钱
dataset3['discount_jian'] = dataset3.discount_rate.apply(get_discount_jian)
#返回优惠券是否是满减券
dataset3['is_man_jian'] = dataset3.discount_rate.apply(is_man_jian)
#显示打折力度
dataset3['discount_rate'] = dataset3.discount_rate.apply(calc_discount_rate)