python 多次读取同样的csv 会发生内存报错 --解决方案

1.多次读取同样的csv时,内存保存,可以通过删除变量且释放内存的形式恢复原有内存

(天池O2O)

#1754884 record,1053282 with coupon_id,9738 coupon. date_received:20160101~20160615,date:20160101~20160630, 539438 users, 8415 merchants
off_train = pd.read_csv('D:/zlp/python example/O2O/ccf_offline_stage1_train.csv',header=None).fillna('null')
off_train.columns = ['user_id','merchant_id','coupon_id','discount_rate','distance','date_received','date']
#2050 coupon_id. date_received:20160701~20160731, 76309 users(76307 in trainset, 35965 in online_trainset), 1559 merchants(1558 in trainset)
off_test = pd.read_csv('D:/zlp/python example/O2O/ccf_offline_stage1_test_revised.csv',header=None)
off_test.columns = ['user_id','merchant_id','coupon_id','discount_rate','distance','date_received']
#11429826 record(872357 with coupon_id),762858 user(267448 in off_train)
on_train = pd.read_csv('D:/zlp/python example/O2O/ccf_online_stage1_train.csv',header=None)
on_train.columns = ['user_id','merchant_id','action','coupon_id','discount_rate','date_received','date']
 

#删除内存

del off_train, off_test , on_train
import gc
gc.collect()

你可能感兴趣的:(python学习系列)