Commit e2a1fb2b authored by Data-韩正辉's avatar Data-韩正辉

17年使用账,需要调整一个product_no,读取数据待优化

parent 18cdf855
......@@ -16,8 +16,8 @@ engine_new_transaction = create_engine(
#假如导出10月份的数据,则end_point 是11月份第一天,watch_point 是10月份最后一天
end_point = '2017-11-01'
watch_point = datetime.date(2017, 10, 31)
end_point = '2017-10-01'
watch_point = datetime.date(2017, 9, 30)
out_file_path = u'E:/审计出表/11月份开始使用表数据/11月份白条出表/在贷/'
query_loan = """
......@@ -209,6 +209,7 @@ df_ali = pd.read_sql(repay_ali % end_point, engine_new_transaction)
df_bank = pd.read_sql(repay_bank % end_point, engine_new_transaction)
df_cash = pd.read_sql(repay_cash % (end_point, end_point), engine_new_transaction)
df_repay = pd.concat([df_online, df_ali, df_bank, df_cash], axis=0, ignore_index=True)
df_repay.dropna(axis=0, inplace=True)
df_loan = df_loan.loc[df_loan['principle'] > 0]
df_info.order_no = df_info.order_no.astype(str)
......@@ -220,10 +221,9 @@ df_repay = df_repay.groupby(['order_no', 'term_no'])['paid_principle'].agg({'sum
df_out = pd.merge(df_loan, df_repay, on=['order_no', 'term_no'], how='left')
df_out['deadline'] = pd.to_datetime(df_out.deadline)
df_out.fillna(0, inplace=True)
# watch_point = datetime.date(2017, 9, 30)
df_out['flag'] = (watch_point-df_out['deadline']).dt.days
df_out=df_out[df_out['flag']>0]
df_out=df_out[df_out['zaidai']>0]
df_out['zaidai'] = df_out['principle'] - df_out['paid_principle']
df_out.loc[df_out['order_no'].isin(
['trainmall1483695024282', 'trainmall1484301600672', 'trainmall1486362269554', 'trainmall1487920296689',
......@@ -231,7 +231,12 @@ df_out.loc[df_out['order_no'].isin(
'trainmall1484301600672', 'trainmall1486362269554', 'grabtrainmall1484650405321', 'trainmall1495785791995',
'trainmall1499935282194', 'trainmall16008368458050561', 'trainmall16008408858634241',
'trainmall16112348780571649', 'trainmall16112552463312897']), 'zaidai'] = 0
#只在17年使用的部分,调账使用
'''
df_out.loc[df_out['product_no']=='300156290067001502503609','flag'] = 1
'''
df_out.loc[(df_out['flag']<=0),'0'] = df_out['zaidai']
df_out.loc[(df_out['flag']>=1) &(df_out['flag']<=30),'01-30'] = df_out['zaidai']
df_out.loc[(df_out['flag']>=31) &(df_out['flag']<=60),'31-60'] = df_out['zaidai']
df_out.loc[(df_out['flag']>=61) &(df_out['flag']<=90),'61-90'] = df_out['zaidai']
......@@ -242,7 +247,7 @@ df_out.loc[(df_out['flag']>=181) &(df_out['flag']<=360),'181-360'] = df_out['zai
df_out.loc[(df_out['flag']>=361),'361+'] = df_out['zaidai']
# df_out['zaidai'] = df_out['zaidai'].apply(lambda x: np.round(x, 2))
df = df_out.groupby(['order_no'])['01-30','31-60','61-90','91-120','121-150','151-180','181-360','361+'].sum().reset_index()
df = df_out.groupby(['order_no'])['0','01-30','31-60','61-90','91-120','121-150','151-180','181-360','361+'].sum().reset_index()
df.fillna(0,inplace=True)
df_loan.order_no = df_loan.order_no.astype(str)
df = pd.merge(df, df_info, on='order_no', how='left')
......@@ -250,7 +255,7 @@ df = pd.merge(df, df_info, on='order_no', how='left')
df.rename(columns={'order_no': u'订单号'
}, inplace=True)
df = df[[u'商户', u'订单号', u'订单金额', u'合同期数', u'放款时间','01-30','31-60','61-90','91-120','121-150','151-180','181-360','361+']]
df = df[[u'商户', u'订单号', u'订单金额', u'合同期数', u'放款时间','0','01-30','31-60','61-90','91-120','121-150','151-180','181-360','361+']]
all_wb = pyexcelerate.Workbook()
for i in xrange(0, len(df), max_limit):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment