怎么解决RuntimeWarning: divide by zero encountered in longlong_scalars stride //= shape[i]的问题?

我用了一个数据划分的算法,划分一个90多万数据的csv文件,但是却出现了RuntimeWarning: divide by zero encountered in longlong_scalars stride //= shape[i]这个问题。然后有文件生成但是没有数据,这是什么原因?

源代码如下: import pandas as pd

train = pd.read_csv('C:/Users/Administrator/Desktop/BDC/bike_old.csv',encoding='gbk')

VIPCARDSN = pd.DataFrame(train.VIPCARDSN.unique()) CARDSN = pd.DataFrame(train.CARDSN.unique()) tm = VIPCARDSN.append(CARDSN,ignore_index=True,verify_integrity=True) tm = tm.drop_duplicates() tm['id_tm'] = tm.index tm.columns = ['VIPCARDSN','id_tm'] train = pd.merge(train,tm,how='left',on = 'VIPCARDSN') train['VIPCARDSN'] = train.id_tm del train['id_tm'] tm.columns = ['CARDSN','id_tm'] train = pd.merge(train,tm,how='left',on = 'CARDSN') train['CARDSN'] = train.id_tm del train['id_tm'] tm.to_csv('carddsn_tm.csv',index=False)

train_ab = ['201505','201506','201507'] test_ab = ['201508'] train_ab_csv = train[train.yearmonth.isin(train_ab)] test_ab_csv = train[train.yearmonth.isin(test_ab)] test_ab_csv['LEASEDATE'] = pd.to_datetime(test_ab_csv.LEASEDATE) del test_ab_csv['yearmonth'] test_ab_csv.LEASETIME = test_ab_csv.LEASETIME.str.split(':').map(lambda x:x[0]).astype(int) >= 12 test_ab_csv['time'] = test_ab_csv.LEASEDATE.dt.date.astype(str) + '-' + test_ab_csv.LEASETIME.astype(int).astype(str) test_comit_jieche = test_ab_csv.groupby(['SHEDID','time'])['USETIME'].count().unstack().fillna(0).stack().reset_index() test_comit_jieche.columns = ['SHEDID','time','LEASE'] test_comit_huanche = test_ab_csv.groupby(['RTSHEDID','time'])['USETIME'].count().unstack().fillna(0).stack().reset_index() test_comit_huanche.columns = ['SHEDID','time','RT'] true = pd.merge(test_comit_huanche,test_comit_jieche,on = ['SHEDID','time'],how = 'outer').fillna(0) train_ab_csv.to_csv('true_chusaibang.csv',index=False) true.to_csv('true_chusaibang.csv',index=False) sample_chusai = true.copy() sample_chusai.RT = 1 sample_chusai.LEASE = 1 sample_chusai.to_csv('sample_chusaibang.csv',index=False)

出现问题: D:\alex\anaconda3\lib\site-packages\pandas\core\reshape\merge.py:1456: RuntimeWarning: divide by zero encountered in longlong_scalars stride //= shape[i]

0 comments