1. 程式人生 > >R語言構建RFM模型瞭解一下~~~

R語言構建RFM模型瞭解一下~~~

np.random.seed(233333)
os.chdir('D:/R/File')
pd.set_option('display.float_format', lambda x: '%.3f' % x) with spss.SavReader('trade.sav',returnHeader = True ,ioUtf8=True,rawMode = True,ioLocale='chinese') as reader:    mydata = pd.DataFrame(list(reader)[1:],columns = list(reader)[0])    mydata['交易日期'] = mydata['交易日期'
].map(lambda x: reader.spss2strDate(x,"%Y-%m-%d", None))    mydata.rename(columns={'訂單ID':'OrderID','客戶ID':'UserID','交易日期':'PayDate','交易金額':'PayAmount'},inplace=True)    start_time = int(time.mktime(time.strptime('2017/01/01', '%Y/%m/%d')))    end_time   = int(time.mktime(time.strptime('2017/12/31', '%Y/%m/%d')))    mydata['PayDate'
] = pd.Series(np.random.randint(start_time,end_time,len(mydata))).map(lambda x: time.strftime("%Y-%m-%d", time.localtime(x)))    
mydata['interval'] = [(datetime.now() - pd.to_datetime(i,format ='%Y %m %d')).days for i in mydata['PayDate']]    
mydata = mydata.astype({'OrderID':'int64','UserID':'int64'
,'PayAmount':'int64'})    
print('---------#######-----------')    
print(mydata.head())    
print('---------#######-----------')    
print(mydata.tail())  
print('…………………………………………………………………………')          
print(mydata.dtypes)    
print('---------#######------------')