1 #!/usr/bin/env python
2 # coding: utf-8
3
4 import numpy as np
5 import pandas as pd
6
7 path='C:/Users/Administrator/Downloads/notebook/order.xls'
8 path1='c:/users/administrator/downloads/notebook/buinfo.xls'
9
10 df_order=pd.read_excel(path,skiprows=1,dtype=object)
11 df_buinfo=pd.read_excel(path1,skiprows=1,dtype=object)
12 df_order1=df_order[['分公司','时间','渠道姓名','订单来源','订单状态','是否电信','竣工时间']]
13 df_buinfo1=df_buinfo[['分公司','账号','是否电信','状态','添加时间']]
14 df_order2=df_order1[(~df_order1.分公司.isin(['测试区局','移动部策划组']))&(~df_order1.时间.str.contains('2018'))]
15
16 df_order2['时间']=pd.to_datetime(df_order2['时间'])
17 df_order2['竣工时间']=pd.to_datetime(df_order2['竣工时间'])
18 df_order2['下单月份']=df_order2.时间.dt.month
19 df_order2['竣工月份']=df_order2.竣工时间.dt.month
20 df_order2['下单日']=df_order2.时间.dt.day
21 df_order2['竣工日']=df_order2.竣工时间.dt.day
22 def cutword(word):
23 position=word.find('分')
24 new_word=word[:position]
25 return new_word
26 df_order2['分公司']=df_order2.分公司.apply(cutword)
27
28 #df_order2[df_order2.分公司.str.contains('开')]
29 df_order2.ix[df_order2.分公司=='开县','分公司']='开州'
30 df_order月下单=df_order2[df_order2['订单状态']!='已重新下单'].groupby(['分公司','下单月份']).订单来源.count().unstack().fillna(0)
31 df_order月下单.loc['合计']=df_order月下单.apply(lambda x:x.sum())
32 df_order月下单.astype(int) #月下单统计
33
34 df_order月激活=df_order2[df_order2.订单状态=='已发佣金'].groupby(['分公司','竣工月份']).订单来源.count().unstack().fillna(0)
35 df_order月激活.loc['合计']=df_order月激活.apply(lambda x:x.sum())
36 df_order月激活.astype(int) #月激活统计
37
38 df_order日下单=df_order2[(df_order2['订单状态']!='已重新下单')&(df_order2.下单月份==10)].groupby(['分公司','下单日']).订单来源.count().unstack().fillna(0)
39 df_order日下单.loc['合计']=df_order日下单.apply(lambda x:x.sum())
40 df_order日下单.astype(int) #日下单统计
41
42 df_order日激活=df_order2[(df_order2['订单状态']=='已发佣金')&(df_order2.竣工月份==10)].groupby(['分公司','竣工日']).订单来源.count().unstack().fillna(0)
43 df_order日激活.loc['合计']=df_order日激活.apply(lambda x:x.sum())
44 df_order日激活.astype(int) #日激活统计
45
46 df_order二级日激活=df_order2[(df_order2['订单状态']=='已发佣金')&(df_order2.竣工月份==10)&(df_order2.是否电信=='否')].groupby(['分公司','竣工日']).订单来源.count().unstack().fillna(0)
47 df_order二级日激活.loc['合计']=df_order二级日激活.apply(lambda x:x.sum())
48 df_order二级日激活.astype(int) #二级日激活统计
49
50 df_buinfo1['添加时间']=pd.to_datetime(df_buinfo1['添加时间'])
51 df_buinfo1['月份']=df_buinfo1.添加时间.dt.month
52 df_buinfo1['日']=df_buinfo1.添加时间.dt.day
53 df_buinfo2=df_buinfo1[(df_buinfo1['添加时间']>='2019-01-01 00:00:00')&(~df_buinfo1.分公司.isin(['测试区局','移动部策划组','黑名单']))]
54 df_buinfo2['分公司']=df_buinfo2.分公司.apply(cutword)
55 df_buinfo2.ix[df_buinfo2.分公司=='开县','分公司']='开州'
56
57 df_buinfo月触点=df_buinfo2[df_buinfo2.是否电信=='否'].groupby(['分公司','月份']).账号.count().unstack().fillna(0)
58 df_buinfo月触点.loc['合计']=df_buinfo月触点.apply(lambda x:x.sum())
59 df_buinfo月触点.astype(int) #触点月报
60
61 df_buinfo触点日报=df_buinfo2[(df_buinfo2.是否电信=='否')&(df_buinfo2.月份==10)].groupby(['分公司','日']).账号.count().unstack().fillna(0)
62 df_buinfo触点日报.loc['合计']=df_buinfo触点日报.apply(lambda x:x.sum())
63 df_buinfo触点日报.astype(int) #触点日报
64
65 df_order3=df_order2[(df_order2['订单状态']=='已发佣金')&(df_order2.是否电信=='否')]
66 df_order4=df_order3[['分公司','渠道姓名','订单来源','是否电信','订单状态','下单月份','竣工月份','下单日','竣工日']]
67 df_order5=df_order4.drop_duplicates(['订单来源'],keep='first')
68
69 df_order有销触点=df_order5.groupby(['分公司','是否电信']).订单来源.count().fillna(0).unstack()
70 df_order有销触点.loc['合计']=df_order有销触点.apply(lambda x:x.sum())
71 df_order有销触点.astype(int) #有销触点
72
73 下单月报=df_order月下单.astype(int) #月下单统计
74 激活月报=df_order月激活.astype(int) #月激活统计
75 下单日报=df_order日下单.astype(int) #日下单统计
76 激活日报=df_order日激活.astype(int) #日激活统计
77 二级激活日报=df_order二级日激活.astype(int) #二级日激活统计
78 触点月报=df_buinfo月触点.astype(int) #触点月报
79 触点日报=df_buinfo触点日报.astype(int) #触点日报
80 有销触点=df_order有销触点.astype(int) #有销触点
81
82 with pd.ExcelWriter('d:/淘卡日报.xlsx',encoding='utf8',index=False) as writer:
83 下单月报.to_excel(writer,sheet_name='下单月报')
84 激活月报.to_excel(writer,sheet_name='激活月报')
85 下单日报.to_excel(writer,sheet_name='下单日报')
86 激活日报.to_excel(writer,sheet_name='激活日报')
87 二级激活日报.to_excel(writer,sheet_name='二级激活日报')
88 触点月报.to_excel(writer,sheet_name='触点月报')
89 触点日报.to_excel(writer,sheet_name='触点日报')
90 有销触点.to_excel(writer,sheet_name='有销触点')
91 print('结果已导出,请到D盘查看:淘卡日报.xlsx')