加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
4G周报新123123.py 76.15 KB
一键复制 编辑 原始数据 按行查看 历史
Mr.T 提交于 2021-12-16 16:49 . 第一次提交
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349
# -*- coding: utf-8 -*-
#conda uninstall enum34
"""
Created on Mon Oct 14 09:56:32 2019
@author: Administrator
"""
from docx.shared import Pt
from docx.enum.style import WD_STYLE_TYPE
from docx.oxml.ns import qn
from docx.shared import Inches
from docx import Document
import xlsxwriter
import numpy as np
import pandas as pd
import os
import matplotlib.pyplot as plt
from openpyxl.styles import Alignment,Font
from openpyxl import Workbook, load_workbook
from openpyxl.drawing.image import Image
import openpyxl
import xlrd,xlsxwriter
from docx.shared import Pt
from math import ceil
import docx
from datetime import datetime
import datetime, time
from datetime import timedelta
plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
path = 'D:/_周报数据'
path_4g='D:/_周报数据/原始数据'+'//'
path_4g_busy='D:/_周报数据/忙时数据'+'//'
path_4g_prb='D:/_周报数据/PRB分析'+'//'
path_out='D:/_周报数据/输出文件'+'//'
pic_path='D:/_周报数据/pic'
os.chdir(path)
def getWeekDaysByNum(m, n):
# 当前日期
now = datetime.datetime.now().date()
dayDict = {}
for x in range(m, n + 1):
#前几周
if x < 0:
lDay = now - timedelta(days=now.weekday() + (7 * abs(x)))
#本周
elif x == 0:
lDay = now - timedelta(days=now.weekday())
#后几周
else:
lDay = now + timedelta(days=(7 - now.weekday()) + 7 * (x - 1))
rDay = lDay + timedelta(days=6)
dayDict[x] = [str(lDay), str(rDay)]
return dayDict
def draw_bar_graph(col1,col2,country_list,pic_name):
y1 = col1.T.values
y2 = col2.T.values
plt.figure(figsize=(12, 4))
x1= range(0,len(country_list))
x2 = [i+0.35 for i in x1]
plt.bar(x1,y1,color='g',width = 0.3,alpha=0.6,label= '上周')
plt.bar(x2,y2,color='b',width = 0.3,alpha=0.6,label= '本周')
for x,y in zip(x1,y1):
plt.text(x, y*1.001, '%d' % y, ha='center', va= 'bottom',fontsize=8)
for x,y in zip(x2,y2 ):
plt.text(x, y*1.001, '%d' % y, ha='center', va= 'bottom',fontsize=8)
plt.xlabel(pic_name)
plt.xticks(range(0,len(country_list)),country_list)
plt.ylabel('区县')
plt.legend(loc='upper middle')
plt.title(pic_name)
plt.savefig('./pic/' + pic_name +".png",format='png', dpi=110)
plt.close()
def draw_bar_graph_float(col1,col2,country_list,pic_name):
y1 = col1.T.values
y2 = col2.T.values
plt.figure(figsize=(12, 4))
x1= range(0,len(country_list))
x2 = [i+0.35 for i in x1]
plt.bar(x1,y1,color='g',width = 0.3,alpha=0.6,label= '上周')
plt.bar(x2,y2,color='b',width = 0.3,alpha=0.6,label= '本周')
for x,y in zip(x1,y1):
plt.text(x, y*1.001, '%.2f' % y, ha='center', va= 'bottom',fontsize=8)
for x,y in zip(x2,y2 ):
plt.text(x, y*1.001, '%.2f' % y, ha='center', va= 'bottom',fontsize=8)
plt.xlabel(pic_name)
plt.xticks(range(0,len(country_list)),country_list)
plt.ylabel('区县')
plt.legend(loc='upper middle')
plt.title(pic_name)
plt.savefig('./pic/' + pic_name +".png",format='png', dpi=110)
plt.close()
def draw_all_pic(df1,df2,country_list):
draw_bar_graph(df1['中文站名'],df2['中文站名'],country_list,'基站数量')
draw_bar_graph(df1['小区名称'],df2['小区名称'],country_list,'扇区数量')
draw_bar_graph(df1['忙时RRC最大连接用户数'],df2['忙时RRC最大连接用户数'],country_list,'忙时RRC用户数')
draw_bar_graph(df1['总流量(GB)'],df2['总流量(GB)'],country_list,'总流量(TB)')
draw_bar_graph_float(df1['下行PRB利用率'],df2['下行PRB利用率'],country_list,'下行PRB利用率(%)')
draw_bar_graph_float(df1['用户体验速率'],df2['用户体验速率'],country_list,'用户体验速率(Mbps)')
draw_bar_graph(df1['下行最大激活用户数'],df2['下行最大激活用户数'],country_list,'下行最大激活用户数')
draw_bar_graph(df1['下行用户面时延'],df2['下行用户面时延'],country_list,'下行用户面时延(ms)')
print('喵喵已经画好各区县汇总图片')
def draw_all_pic_country(df1,df2,zhiju_list,county):
draw_bar_graph(df1['中文站名'],df2['中文站名'],zhiju_list,county + '基站数量')
draw_bar_graph(df1['小区名称'],df2['小区名称'],zhiju_list,county + '扇区数量')
draw_bar_graph(df1['忙时RRC最大连接用户数'],df2['忙时RRC最大连接用户数'],zhiju_list,county + '忙时RRC用户数')
draw_bar_graph(df1['总流量(GB)'],df2['总流量(GB)'],zhiju_list,county + '总流量(TB)')
draw_bar_graph_float(df1['下行PRB利用率'],df2['下行PRB利用率'],zhiju_list,county + '下行PRB利用率(%)')
draw_bar_graph_float(df1['用户体验速率'],df2['用户体验速率'],zhiju_list,county + '用户体验速率(Mbps)')
draw_bar_graph(df1['下行最大激活用户数'],df2['下行最大激活用户数'],zhiju_list,county + '下行最大激活用户数')
draw_bar_graph(df1['下行用户面时延'],df2['下行用户面时延'],zhiju_list,county + '下行用户面时延(ms)')
print('喵喵已经画好'+county+'支局图片')
def huanhang(cell):
cell.alignment = Alignment(horizontal='general',
vertical='bottom',
text_rotation=0,
wrap_text=True,
shrink_to_fit=True,
indent=0)
cell.font = Font(name='Calibri',
size=11,
color='FF000000',
bold=False,
italic=False,
vertAlign=None,
underline='none',
strike=False)
def chuli(filename,sheetname):
wb = load_workbook('./输出文件/'+filename)
ws = wb[sheetname]
a=list(ws[1])
for cell in a:
huanhang(cell)
wb.save('./输出文件/'+ filename)
print('喵喵已经把'+filename+'的'+sheetname+'自动转行好了')
def huatu(filename,sheetname,country):
wb=load_workbook('./输出文件/'+filename)
ws1=wb[sheetname]
img = Image('./pic/' +country +"基站数量.png")
ws1.add_image(img, 'A1')
img = Image('./pic/' + country +"忙时RRC用户数.png")
ws1.add_image(img, 'A26')
img = Image('./pic/' +country + "扇区数量.png")
ws1.add_image(img, 'A51')
img = Image('./pic/' +country + "总流量(TB).png")
ws1.add_image(img, 'A77')
img = Image('./pic/' +country + "下行PRB利用率(%).png")
ws1.add_image(img, 'A100')
img = Image('./pic/' +country + "用户体验速率(Mbps).png")
ws1.add_image(img, 'A126')
img = Image('./pic/' +country + "下行最大激活用户数.png")
ws1.add_image(img, 'A150')
img = Image('./pic/' +country + "下行用户面时延(ms).png")
ws1.add_image(img, 'A176')
wb.save('./输出文件/'+filename)
print('喵喵已经把'+country+filename+'图贴好了')
def huatu2(filename,sheetname):
wb=load_workbook('./输出文件/'+filename)
ws1=wb[sheetname]
img = Image('./pic/' +"基站数量.png")
ws1.add_image(img, 'A1')
img = Image('./pic/' + "忙时RRC用户数.png")
ws1.add_image(img, 'A26')
img = Image('./pic/' + "扇区数量.png")
ws1.add_image(img, 'A51')
img = Image('./pic/' + "总流量(TB).png")
ws1.add_image(img, 'A77')
img = Image('./pic/' + "下行PRB利用率(%).png")
ws1.add_image(img, 'A100')
img = Image('./pic/' + "用户体验速率(Mbps).png")
ws1.add_image(img, 'A126')
img = Image('./pic/' + "下行最大激活用户数.png")
ws1.add_image(img, 'A150')
img = Image('./pic/' + "下行用户面时延(ms).png")
ws1.add_image(img, 'A176')
wb.save('./输出文件/'+filename)
print('喵喵已经把'+filename+'的图贴好了')
def jzjz(yhs):
if yhs>=90:
return '超高价值基站'
elif yhs>=60 and yhs<90 :
return '高等价值基站'
elif yhs>=30 and yhs<60 :
return '中等价值基站'
elif yhs>=10 and yhs<30:
return '低等价值基站'
elif yhs<10 :
return '超低价值基站'
print('喵喵已经把基站价值给计算出来了')
def jzsl(bzjzs,szjzs):
if bzjzs-szjzs>0:
return '增加'+str(round(bzjzs-szjzs,2))
elif bzjzs-szjzs<0:
return '减少'+str(round(szjzs-bzjzs,2))
elif bzjzs-szjzs==0:
return '不变'
df_enodeb_name = pd.read_excel('物理站址清单.xlsx',encoding = 'utf-8')
df_PRB_titles = pd.read_excel('BT.xlsx',encoding = 'utf-8')
PRB_titles = list(df_PRB_titles.columns)
df_eric_titles = pd.read_excel('爱立信表头.xlsx',encoding = 'utf-8')
titles = list(df_eric_titles.columns)
#print(titles)
df_eric_busy_titles = pd.read_excel('爱立信表头忙时.xlsx',encoding = 'utf-8')
busy_titles = list(df_eric_busy_titles.columns)
#print(busy_titles)
files_4G = os.listdir(path_4g)
zte_4G_files = [x for x in files_4G if '历史性能' in x]
eric_4G_files = [x for x in files_4G if '爱立信' in x]
files_4G_busy = os.listdir(path_4g_busy)
zte_4G_busy_files = [x for x in files_4G_busy if '历史性能' in x]
eric_4G_busy_files = [x for x in files_4G_busy if '爱立信' in x]
files_4G_prb = os.listdir(path_4g_prb)
zte_prb_files = [x for x in files_4G_prb if 'qj' in x]
eric_prb_files = [x for x in files_4G_prb if '爱立信' in x]
# =============================================================================
# #爱立信数据处理
# =============================================================================
df_eric_4G_traffic = pd.DataFrame()
for file in eric_4G_files:
df_tmp = pd.read_csv(path_4g + file,header = None , names = titles, engine = 'python', encoding = 'gbk')
df_tmp.fillna(0,inplace=True)
df_tmp['eNodeB'] = df_tmp['eNodeB'].map(lambda x:x.replace('\'',''))
df_tmp['week'] = df_tmp['week'].map(lambda x:x-1)
df_tmp['小区号'] = df_tmp['eNodeB'].map(lambda x:x.replace('\'',''))+'_'+df_tmp['EUTRANCELLFDD'].map(lambda x:x.split('_')[1])
df_tmp['EUTRANCELLFDD'] = df_tmp['EUTRANCELLFDD'].map(lambda x:x.replace('\'',''))
#a=list(df_eric_titles.columns)
#print(a)
df_tmp.rename(columns={'eNodeB':'网元',
'EUTRANCELLFDD':'小区名称',
'Air Interface_Traffic_Volume_UL_MBytes':'上行流量(GB)',
'Air Interface_Traffic_Volume_DL_MBytes':'下行流量(GB)'},inplace =True)
df_tmp['上行流量(GB)']=round(df_tmp['上行流量(GB)']/1024,2)
df_tmp['下行流量(GB)']=round(df_tmp['下行流量(GB)']/1024,2)
df_tmp['总流量(GB)'] =round(df_tmp['上行流量(GB)'] + df_tmp['下行流量(GB)'],2)
df_tmp=df_tmp[['week','网元','小区号','小区名称','上行流量(GB)','下行流量(GB)','总流量(GB)']]
df_tmp=pd.merge(df_tmp,df_enodeb_name,how ='left',on = '小区号' )
df_eric_4G_traffic = df_eric_4G_traffic.append(df_tmp)
# =============================================================================
# #爱立信忙时数据处理
# =============================================================================
df_eric_4G_traffic_busy=pd.DataFrame()
for file in eric_4G_busy_files:
df_tmp = pd.read_csv(path_4g_busy + file,header = None,names = busy_titles, engine = 'python', encoding = 'gbk',index_col=False)
df_tmp.fillna(0,inplace=True)
df_tmp['DATE_ID'] = df_tmp['DATE_ID'].map(lambda x:x.replace('\'',''))
df_tmp['week']= pd.to_datetime(df_tmp['DATE_ID'])
df_tmp['week']=df_tmp['week'].map(lambda x:x.isocalendar()[1])
df_tmp['eNodeB'] = df_tmp['eNodeB'].map(lambda x:x.replace('\'',''))
df_tmp['小区号'] = df_tmp['eNodeB'].map(lambda x:x.replace('\'',''))+'_'+df_tmp['EUTRANCELLFDD'].map(lambda x:x.split('_')[1])
df_tmp['EUTRANCELLFDD'] = df_tmp['EUTRANCELLFDD'].map(lambda x:x.replace('\'',''))
#a=list(df_eric_busy_titles.columns)
#print(a)
df_tmp.rename(columns={'EUTRANCELLFDD':'小区名称',
'Max number of UE in RRc':'忙时RRC最大连接用户数',},inplace =True)
df_tmp=df_tmp[['week','小区号','忙时RRC最大连接用户数']]
df_eric_4G_traffic_busy=df_eric_4G_traffic_busy.append(df_tmp)
# =============================================================================
# #爱立信数据合并
# =============================================================================
df_eric_4G_traffic['标记']=df_eric_4G_traffic['week'].map(str)+'_'+df_eric_4G_traffic['小区号'].map(str)
df_eric_4G_traffic_busy['标记']=df_eric_4G_traffic_busy['week'].map(str)+'_'+df_eric_4G_traffic_busy['小区号'].map(str)
df_eric_4G_traffic_busy=df_eric_4G_traffic_busy.drop(columns=['week','小区号' ])
df_eric=pd.merge(df_eric_4G_traffic,df_eric_4G_traffic_busy,how ='left',on = '标记',)
df_eric=df_eric.drop(columns=['标记'])
# =============================================================================
# #中兴数据处理
# =============================================================================
df_zte_4G_traffic = pd.DataFrame()
for file in zte_4G_files:
df_tmp = pd.read_csv(path_4g + file,skiprows = 5,engine = 'python', encoding = 'gbk')
df_tmp.fillna(0,inplace=True)
df_tmp['日期'] = df_tmp['结束时间'].map(lambda x:str(x).split(' ')[0])
df_tmp['周'] =pd.to_datetime(df_tmp['日期'])
df_tmp['week'] = df_tmp['周'].map(lambda x:x.isocalendar()[1])
df_tmp['小区号']=df_tmp['网元'].map(str)+'_'+df_tmp['小区'].map(str)
df_tmp['空口上行用户面流量(MByte)_1'] = df_tmp['空口上行用户面流量(MByte)_1'].map(lambda x:float(x.replace(',','')))
df_tmp['空口下行用户面流量(MByte)_1477070755617-11'] = df_tmp['空口下行用户面流量(MByte)_1477070755617-11'].map(lambda x:float(x.replace(',','')))
#a=list(df_tmp.columns)
#print(a)
df_tmp.rename(columns={'空口上行用户面流量(MByte)_1':'上行流量(GB)',
'空口下行用户面流量(MByte)_1477070755617-11':'下行流量(GB)'},inplace =True)
df_tmp['上行流量(GB)']=round(df_tmp['上行流量(GB)']/1024,2)
df_tmp['下行流量(GB)']=round(df_tmp['下行流量(GB)']/1024,2)
df_tmp['总流量(GB)'] =round(df_tmp['上行流量(GB)'] + df_tmp['下行流量(GB)'],2)
df_tmp=df_tmp[['week','网元','小区号','小区名称','上行流量(GB)','下行流量(GB)','总流量(GB)']]
df_tmp=pd.merge(df_tmp,df_enodeb_name,how ='left',on = '小区号' )
df_zte_4G_traffic=df_zte_4G_traffic.append(df_tmp)
# =============================================================================
# #中兴忙时数据处理
# =============================================================================
df_zte_4G_traffic_buys = pd.DataFrame()
for file in zte_4G_busy_files:
df_tmp = pd.read_csv(path_4g_busy + file,skiprows = 5,engine = 'python', encoding = 'gbk')
df_tmp.fillna(0,inplace=True)
df_tmp['日期'] = df_tmp['结束时间'].map(lambda x:str(x).split(' ')[0])
df_tmp['周'] =pd.to_datetime(df_tmp['日期'])
df_tmp['week'] = df_tmp['周'].map(lambda x:x.isocalendar()[1])
df_tmp['小区号']=df_tmp['网元'].map(str)+'_'+df_tmp['小区'].map(str)
#a=list(df_tmp.columns)
#print(a)
df_tmp.rename(columns={'最大RRC连接用户数_1':'忙时RRC最大连接用户数',},inplace =True)
df_tmp=df_tmp[['week','小区号','忙时RRC最大连接用户数']]
df_zte_4G_traffic_buys=df_zte_4G_traffic_buys.append(df_tmp)
# =============================================================================
# #中兴数据合并
# =============================================================================
df_zte_4G_traffic['标记']=df_zte_4G_traffic['week'].map(str)+'_'+df_zte_4G_traffic['小区号'].map(str)
df_zte_4G_traffic_buys['标记']=df_zte_4G_traffic_buys['week'].map(str)+'_'+df_zte_4G_traffic_buys['小区号'].map(str)
df_zte_4G_traffic_buys=df_zte_4G_traffic_buys.drop(columns=['week','小区号' ])
df_zte=pd.merge(df_zte_4G_traffic,df_zte_4G_traffic_buys,how ='left',on = '标记',)
df_zte=df_zte.drop(columns=['标记'])
#中兴爱立信数据合并
df_traffic=df_eric.append(df_zte)
# =============================================================================
# #爱立信PRB数据处理
# =============================================================================
df_eric_4G_PRB = pd.DataFrame()
for file in eric_prb_files:
df_tmp = pd.read_csv(path_4g_prb + file,header = None,names = PRB_titles, engine = 'python', encoding = 'gbk')
df_tmp.fillna(0,inplace=True)
df_tmp['DATE_ID']=df_tmp['DATE_ID'].map(lambda x:x.replace('\'',''))
df_tmp['eNodeB'] = df_tmp['eNodeB'].map(lambda x:x.replace('\'',''))
df_tmp['EUTRANCELLFDD'] = df_tmp['EUTRANCELLFDD'].map(lambda x:x.replace('\'',''))
#a=list(df_tmp.columns)
#print(a)
df_tmp.rename(columns={'eNodeB':'网元',
'EUTRANCELLFDD':'小区名称',
'DATE_ID':'日期',
'Max Number of DL Active Users':'下行最大激活用户数',
'Max Number of UL Active Users':'上行最大激活用户数',
'DL_Util_of_PRB':'下行PRB利用率',
'DL user timer(ms)':'下行用户面时延',
'Avg User Fell Throughput (Mbps)':'用户体验速率'},inplace =True)
df_tmp['week'] =pd.to_datetime(df_tmp['日期'])
df_tmp['week'] = df_tmp['week'].map(lambda x:x.isocalendar()[1])
df_eric_4G_PRB=df_eric_4G_PRB.append(df_tmp)#合并两个表格
# =============================================================================
# #按天透视,找出每周每个小区最忙的小时
# =============================================================================
df_pivot_day = pd.pivot_table(df_eric_4G_PRB, index=['week','日期','小区名称'],
values = ['下行最大激活用户数', '下行PRB利用率','下行用户面时延','用户体验速率'],
aggfunc = {'下行最大激活用户数':np.max,
'下行PRB利用率':np.max,
'下行用户面时延':np.max,
'用户体验速率':np.min})
df_pivot_day = df_pivot_day.reset_index()
# =============================================================================
# #按周透视,找出每个小区每周最忙
# =============================================================================
df_pivot_week =pd.pivot_table(df_pivot_day,index=['week','小区名称'],
values = ['下行最大激活用户数', '下行PRB利用率','下行用户面时延','用户体验速率'],
aggfunc = {'下行最大激活用户数':np.mean,
'下行PRB利用率':np.mean,
'下行用户面时延':np.mean,
'用户体验速率':np.mean})
df_pivot_day.dtypes
df_pivot_week = df_pivot_week.reset_index()
df_eric_prb=df_pivot_week
df_eric_prb['下行PRB利用率']=df_eric_prb['下行PRB利用率']*100
# =============================================================================
# #中兴PRB数据处理
# =============================================================================
df_zte_4G_PRB = pd.DataFrame()
for file in zte_prb_files:
df_tmp = pd.read_csv(path_4g_prb + file,engine = 'python', encoding = 'gbk')
df_tmp.fillna(0,inplace=True)
#a=df_tmp.columns
#print(a)
df_tmp.rename(columns={'开始时间':'日期',
'最大激活用户数_1':'下行最大激活用户数',
'下行PRB平均占用率_1':'下行PRB利用率',
'用户面下行包平均时延':'下行用户面时延',
'分QCI用户体验下行平均速率(Mbps)_1':'用户体验速率'},inplace =True)
df_tmp['日期'] = df_tmp['日期'].map(lambda x:str(x).split(' ')[0])
df_tmp['week'] =pd.to_datetime(df_tmp['日期'])
df_tmp['week'] = df_tmp['week'].map(lambda x:x.isocalendar()[1])
df_zte_4G_PRB=df_zte_4G_PRB.append(df_tmp)#合并两个表格
df_zte_4G_PRB['下行PRB利用率'] = df_zte_4G_PRB['下行PRB利用率'].map(lambda x:float(str(x).split('%')[0]))
# =============================================================================
# #按天透视,找出每周每个小区最忙的小时
# =============================================================================
df_pivot_day = pd.pivot_table(df_zte_4G_PRB, index=['week','日期','小区名称'],
values = ['下行最大激活用户数', '下行PRB利用率','下行用户面时延','用户体验速率'],
aggfunc = {'下行最大激活用户数':np.max,
'下行PRB利用率':np.max,
'下行用户面时延':np.max,
'用户体验速率':np.min})
df_pivot_day = df_pivot_day.reset_index()
# =============================================================================
# #按周透视,找出每个小区每周最忙
# =============================================================================
df_pivot_week =pd.pivot_table(df_pivot_day,index=['week','小区名称'],
values = ['下行最大激活用户数', '下行PRB利用率','下行用户面时延','用户体验速率'],
aggfunc = {'下行最大激活用户数':np.mean,
'下行PRB利用率':np.mean,
'下行用户面时延':np.mean,
'用户体验速率':np.mean})
df_pivot_week = df_pivot_week.reset_index()
df_zte_prb=df_pivot_week
df_prb=df_zte_prb.append(df_eric_prb)
# =============================================================================
# ##汇总总表
# =============================================================================
df_traffic['标记']=df_traffic['week'].map(str)+'_'+df_traffic['小区名称'].map(str)
df_prb['标记']=df_prb['week'].map(str)+'_'+df_prb['小区名称'].map(str)
df_prb=df_prb.drop(columns=['week','小区名称' ])
df_zongbiao=pd.merge(df_traffic,df_prb,how ='left',on = '标记',)
df_zongbiao=df_zongbiao.drop(columns=['标记'])
# =============================================================================
# #处理总表数据
# =============================================================================
df_zongbiao=df_zongbiao.fillna(0)
# =============================================================================p
# #按物理站址透视上周数据
# =============================================================================
#a=list(df_zongbiao_lastweek.columns)
#print(a)
df_eNodeb =pd.pivot_table(df_zongbiao,index=['week','网元','区县','中文站名','区域','频段','支局'],
values = ['总流量(GB)',
'下行流量(GB)',
'上行流量(GB)',
'忙时RRC最大连接用户数',
'下行最大激活用户数',
'下行PRB利用率',
'下行用户面时延',
'小区名称',
'用户体验速率'],
aggfunc = {'下行最大激活用户数':np.sum,
'忙时RRC最大连接用户数':np.sum,
'下行流量(GB)':np.sum,
'上行流量(GB)':np.sum,
'总流量(GB)':np.sum,
'下行PRB利用率':np.mean,
'下行用户面时延':np.max,
'小区名称':len,
'用户体验速率':np.min})
df_eNodeb = df_eNodeb.reset_index()
# =============================================================================
# 按区县统计上周
# =============================================================================
#a=list(df_eNodeb_last.columns)
#print(a)
df_country =pd.pivot_table(df_eNodeb,index=['week','区县'],
values = ['总流量(GB)',
'下行流量(GB)',
'上行流量(GB)',
'忙时RRC最大连接用户数',
'下行最大激活用户数',
'下行PRB利用率',
'下行用户面时延',
'中文站名',
'小区名称',
'用户体验速率'],
aggfunc = {'下行最大激活用户数':np.sum,
'忙时RRC最大连接用户数':np.sum,
'下行流量(GB)':np.sum,
'上行流量(GB)':np.sum,
'总流量(GB)':np.sum,
'下行PRB利用率':np.mean,
'下行用户面时延':np.mean,
'小区名称':np.sum,
'中文站名':len,
'用户体验速率':np.mean})
df_country = df_country.reset_index()
# =============================================================================
# 全市指标
# =============================================================================
df_city =pd.pivot_table(df_country,index=['week'],
values = ['总流量(GB)',
'下行流量(GB)',
'上行流量(GB)',
'忙时RRC最大连接用户数',
'下行最大激活用户数',
'下行PRB利用率',
'下行用户面时延',
'中文站名',
'小区名称',
'用户体验速率'],
aggfunc = {'下行最大激活用户数':np.sum,
'忙时RRC最大连接用户数':np.sum,
'下行流量(GB)':np.sum,
'上行流量(GB)':np.sum,
'总流量(GB)':np.sum,
'下行PRB利用率':np.mean,
'下行用户面时延':np.mean,
'小区名称':np.sum,
'中文站名':np.sum,
'用户体验速率':np.mean})
df_city.reset_index(inplace =True)
df_city['区县'] = '全市'
df_country = df_country.append(df_city)
# =============================================================================
# #处理两周数据
# =============================================================================
week_list = list(set(df_country['week']))
df_country_lastweek = df_country[df_country['week'] == week_list[0]]
df_country_lastweek = df_country_lastweek.drop(columns=['week'])
df_country_thisweek = df_country[df_country['week'] == week_list[1]]
df_country_thisweek = df_country_thisweek.drop(columns=['week'])
df_country_lastweek['总流量(GB)']=round(df_country_lastweek['总流量(GB)']/1024,2)
df_country_thisweek['总流量(GB)']=round(df_country_thisweek['总流量(GB)']/1024,2)
country_list = list(df_country_lastweek['区县'])
draw_all_pic(df_country_lastweek,df_country_thisweek,country_list)
country_list.remove('全市')
for country in country_list:
df_tmp = df_zongbiao[df_zongbiao['区县'] == country]
df_zhiju_bts =pd.pivot_table(df_tmp,index=['week','区县','支局','中文站名',],
values = ['总流量(GB)',
'下行流量(GB)',
'上行流量(GB)',
'忙时RRC最大连接用户数',
'下行最大激活用户数',
'下行PRB利用率',
'下行用户面时延',
'小区名称',
'用户体验速率'],
aggfunc = {'下行最大激活用户数':np.sum,
'忙时RRC最大连接用户数':np.sum,
'下行流量(GB)':np.sum,
'上行流量(GB)':np.sum,
'总流量(GB)':np.sum,
'下行PRB利用率':np.mean,
'下行用户面时延':np.max,
'小区名称':len,
'用户体验速率':np.min})
df_zhiju_bts.reset_index(inplace =True)
df_zhiju =pd.pivot_table(df_zhiju_bts,index=['week','区县','支局'],
values = ['总流量(GB)',
'下行流量(GB)',
'上行流量(GB)',
'忙时RRC最大连接用户数',
'下行最大激活用户数',
'下行PRB利用率',
'下行用户面时延',
'中文站名',
'小区名称',
'用户体验速率'],
aggfunc = {'下行最大激活用户数':np.sum,
'忙时RRC最大连接用户数':np.sum,
'下行流量(GB)':np.sum,
'上行流量(GB)':np.sum,
'总流量(GB)':np.sum,
'下行PRB利用率':np.mean,
'下行用户面时延':np.mean,
'中文站名':len,
'小区名称':np.sum,
'用户体验速率':np.mean})
df_zhiju.reset_index(inplace =True)
# =============================================================================
# 全县指标
# =============================================================================
df_country_all =pd.pivot_table(df_zhiju,index=['week'],
values = ['总流量(GB)',
'下行流量(GB)',
'上行流量(GB)',
'忙时RRC最大连接用户数',
'下行最大激活用户数',
'下行PRB利用率',
'下行用户面时延',
'中文站名',
'小区名称',
'用户体验速率'],
aggfunc = {'下行最大激活用户数':np.sum,
'忙时RRC最大连接用户数':np.sum,
'下行流量(GB)':np.sum,
'上行流量(GB)':np.sum,
'总流量(GB)':np.sum,
'下行PRB利用率':np.mean,
'下行用户面时延':np.mean,
'小区名称':np.sum,
'中文站名':np.sum,
'用户体验速率':np.mean})
# =============================================================================
# 加入全县指标
# =============================================================================
df_country_all.reset_index(inplace =True)
df_country_all['支局'] = '全县'
df_country_all['区县'] = '全县'
df_zhiju = df_zhiju.append(df_country_all)
# =============================================================================
# 循环出表
# =============================================================================
week_list = list(set(df_zhiju['week']))
df_zhiju_lastweek = df_zhiju[df_zhiju['week'] == week_list[0]]
df_zhiju_lastweek = df_zhiju_lastweek.drop(columns=['week'])
df_zhiju_thisweek = df_zhiju[df_zhiju['week'] == week_list[1]]
df_zhiju_thisweek = df_zhiju_thisweek.drop(columns=['week'])
zhiju_list = list(df_zhiju_lastweek['支局'])
draw_all_pic_country(df_zhiju_lastweek,df_zhiju_thisweek,zhiju_list,country)
df_zhiju_lastweek.reset_index(inplace =True)
df_zhiju_thisweek.reset_index(inplace =True)
df_zhiju_lastweek.drop('index',axis=1,inplace =True)
df_zhiju_thisweek.drop('index',axis=1,inplace =True)
df_zhiju_lastweek.rename(columns={'中文站名':'基站数',
'小区名称':'扇区数'},inplace =True)
df_zhiju_thisweek.rename(columns={'中文站名':'基站数',
'小区名称':'扇区数'},inplace =True)
df_zhiju_lastweek.columns=df_zhiju_lastweek.columns.map(lambda x:x + '_上周')
df_zhiju_thisweek.columns=df_zhiju_thisweek.columns.map(lambda x:x + '_本周')
df_all=pd.concat([df_zhiju_lastweek,df_zhiju_thisweek],axis=1)
df_all=df_all[['区县_上周',
'支局_上周',
'上行流量(GB)_上周','上行流量(GB)_本周',
'下行PRB利用率_上周','下行PRB利用率_本周',
'下行最大激活用户数_上周','下行最大激活用户数_本周',
'下行流量(GB)_上周','下行流量(GB)_本周',
'下行用户面时延_上周','下行用户面时延_本周',
'基站数_上周','基站数_本周',
'扇区数_上周','扇区数_本周','忙时RRC最大连接用户数_上周',
'忙时RRC最大连接用户数_本周',
'总流量(GB)_上周','总流量(GB)_本周',
'用户体验速率_上周','用户体验速率_本周']]
df_all.rename(columns={'区县_上周':'区县',
'支局_上周':'支局'},inplace =True)
df_qindang=df_tmp
df_qindang=df_qindang[df_qindang['week'] == week_list[1]]
df_qindang = df_qindang.drop(columns=['week'])
df_tmp = df_zongbiao[df_zongbiao['区县'] == country]
df_all['下行最大激活用户数_上周']=df_all['下行最大激活用户数_上周'].astype(int)
df_all['下行最大激活用户数_本周']=df_all['下行最大激活用户数_本周'].astype(int)
with pd.ExcelWriter(path_out + country +'按支局详单' + '.xlsx') as writer: #输出到excel
book = writer.book # 将图片插入到excel表格中
sheet = book.add_worksheet('各区县用户数及流量')
df_all.to_excel(writer,'两周数据对比')
df_qindang.to_excel(writer,'小区清单')
print('喵喵已经把'+country+'支局表做好了')
chuli(country +'按支局详单' + '.xlsx','小区清单')
chuli(country +'按支局详单' + '.xlsx','两周数据对比')
huatu(country +'按支局详单' + '.xlsx','各区县用户数及流量',country)
df_country_lastweek.reset_index(inplace =True)
df_country_thisweek.reset_index(inplace =True)
df_country_lastweek.drop('index',axis=1,inplace =True)
df_country_thisweek.drop('index',axis=1,inplace =True)
df_country_lastweek.rename(columns={'中文站名':'基站数',
'小区名称':'扇区数'},inplace =True)
df_country_thisweek.rename(columns={'中文站名':'基站数',
'小区名称':'扇区数'},inplace =True)
df_country_lastweek.columns=df_country_lastweek.columns.map(lambda x:x + '_上周')
df_country_thisweek.columns=df_country_thisweek.columns.map(lambda x:x + '_本周')
#print(df_country_lastweek.columns)
#print(df_country_thisweek.columns)
df_all_county=pd.concat([df_country_lastweek,df_country_thisweek],axis=1)
df_all_county=df_all_county[['区县_上周',
'上行流量(GB)_上周','上行流量(GB)_本周',
'下行流量(GB)_上周','下行流量(GB)_本周',
'总流量(GB)_上周','总流量(GB)_本周',
'下行PRB利用率_上周','下行PRB利用率_本周',
'下行最大激活用户数_上周','下行最大激活用户数_本周',
'忙时RRC最大连接用户数_上周','忙时RRC最大连接用户数_本周',
'下行用户面时延_上周','下行用户面时延_本周',
'基站数_上周','基站数_本周',
'扇区数_上周','扇区数_本周',
'用户体验速率_上周','用户体验速率_本周']]
df_all_county.rename(columns={'区县_上周':'区县'},inplace =True)
df_qindang_county=df_zongbiao
df_qindang_county=df_qindang_county[df_qindang_county['week'] == week_list[1]]
df_qindang_county = df_qindang_county.drop(columns=['week'])
df_eNodeb=df_eNodeb[df_eNodeb['week']== week_list[1]]
df_eNodeb.rename(columns={'小区名称':'扇区数'},inplace =True)
df_eNodeb=df_eNodeb.drop(columns=['week'])
pinduan_list = list(set(df_eNodeb['频段']))
cj_list = list(set(df_eNodeb['区域']))
df_eNodeb1 = df_eNodeb[df_eNodeb['频段'] == 'L800']
df_eNodeb1=df_eNodeb1[df_eNodeb1['区域'] == '爱立信' ]
df_eNodeb1['价值']=df_eNodeb1['忙时RRC最大连接用户数'].map(lambda x:jzjz(x))
df_eNodeb2=pd.pivot_table(df_eNodeb1,index=['区县'],
values = ['中文站名'],
aggfunc = {'中文站名':len})
df_eNodeb2.fillna(0,inplace=True)
df_eNodeb2.reset_index(inplace =True)
df_eNodeb2.loc['9'] = df_eNodeb2.apply(lambda x: x.sum())
df_eNodeb2.at['9','区县']='全市'
df_jz=pd.pivot_table(df_eNodeb1,index=['区县'],
columns=["价值"],
aggfunc = {'价值':len})
df_jz.fillna(0,inplace=True)
df_jz.reset_index(inplace =True)
df_jz.loc['9'] = df_jz.apply(lambda x: x.sum())
df_jz.at['9','区县']='全市'
df_jz2=pd.merge(df_jz,df_eNodeb2,how ='left',on = '区县',)
df_jz2.columns=['区县',
'区县2',
'中等价值基站(用户数大于等于30个且小于60)',
'低等价值基站(用户数大于等于10个且小于30)',
'超低价值基站(用户数小于10个)',
'超高价值基站(用户数大于等于90个)',
'高等价值基站(用户数大于等于60个且小于90)',
'L800M站址数']
df_jz2=df_jz2.drop(columns=['区县2'])
df_jz2['超低价值基站占比(%)']=df_jz2['超低价值基站(用户数小于10个)']/df_jz2['L800M站址数']
df_jz2['低等价值基站占比(%)']=df_jz2['低等价值基站(用户数大于等于10个且小于30)']/df_jz2['L800M站址数']
df_jz2['中等价值基站占比(%)']=df_jz2['中等价值基站(用户数大于等于30个且小于60)']/df_jz2['L800M站址数']
df_jz2['高等价值基站占比(%)']=df_jz2['高等价值基站(用户数大于等于60个且小于90)']/df_jz2['L800M站址数']
df_jz2['超高价值基站占比(%)']=df_jz2['超高价值基站(用户数大于等于90个)']/df_jz2['L800M站址数']
df_jz2.columns=['区县',
'中等价值基站(用户数大于等于30个且小于60)',
'低等价值基站(用户数大于等于10个且小于30)',
'超低价值基站(用户数小于10个)',
'超高价值基站(用户数大于等于90个)',
'高等价值基站(用户数大于等于60个且小于90)',
'L800M站址数',
'超低价值基站占比(%)',
'低等价值基站占比(%)',
'中等价值基站占比(%)',
'高等价值基站占比(%)',
'超高价值基站占比(%)']
df_jz2=df_jz2[['区县',
'超低价值基站(用户数小于10个)',
'超低价值基站占比(%)',
'低等价值基站(用户数大于等于10个且小于30)',
'低等价值基站占比(%)',
'中等价值基站(用户数大于等于30个且小于60)',
'中等价值基站占比(%)',
'高等价值基站(用户数大于等于60个且小于90)',
'高等价值基站占比(%)',
'超高价值基站(用户数大于等于90个)',
'超高价值基站占比(%)',
'L800M站址数']]
#print(df_all_county.columns)
df_all_county['上行流量(GB)_上周']=round(df_all_county['上行流量(GB)_上周']/1024,2)
df_all_county['上行流量(GB)_本周']=round(df_all_county['上行流量(GB)_本周']/1024,2)
df_all_county['下行流量(GB)_上周']=round(df_all_county['下行流量(GB)_上周']/1024,2)
df_all_county['下行流量(GB)_本周']=round(df_all_county['下行流量(GB)_本周']/1024,2)
df_all_county['总流量(GB)_上周']=round(df_all_county['总流量(GB)_上周'],2)
df_all_county['总流量(GB)_本周']=round(df_all_county['总流量(GB)_本周'],2)
df_all_county['下行PRB利用率_上周']=round(df_all_county['下行PRB利用率_上周'],2)
df_all_county['下行PRB利用率_本周']=round(df_all_county['下行PRB利用率_本周'],2)
df_all_county['下行最大激活用户数_上周']=round(df_all_county['下行最大激活用户数_上周'],2)
df_all_county['下行最大激活用户数_本周']=round(df_all_county['下行最大激活用户数_本周'],2)
df_all_county['下行用户面时延_上周']=round(df_all_county['下行用户面时延_上周'],0)
df_all_county['下行用户面时延_本周']=round(df_all_county['下行用户面时延_本周'],0)
df_all_county['用户体验速率_上周']=round(df_all_county['用户体验速率_上周'],2)
df_all_county['用户体验速率_本周']=round(df_all_county['用户体验速率_本周'],2)
df_all_county['忙时RRC最大连接用户数_上周']=round(df_all_county['忙时RRC最大连接用户数_上周'],0)
df_all_county['忙时RRC最大连接用户数_本周']=round(df_all_county['忙时RRC最大连接用户数_本周'],0)
df_all_county.rename(columns={'上行流量(GB)_上周':'上行流量(TB)_上周',
'上行流量(GB)_本周':'上行流量(TB)_本周',
'下行流量(GB)_上周':'下行流量(TB)_上周',
'下行流量(GB)_本周':'下行流量(TB)_本周',
'总流量(GB)_上周':'总流量(TB)_上周',
'总流量(GB)_本周':'总流量(TB)_本周'},inplace =True)
df_qindang_county['下行PRB利用率']=round(df_qindang_county['下行PRB利用率'],2)
df_qindang_county['下行最大激活用户数']=round(df_qindang_county['下行最大激活用户数'],2)
df_qindang_county['下行用户面时延']=round(df_qindang_county['下行用户面时延'],0)
df_qindang_county['用户体验速率']=round(df_qindang_county['用户体验速率'],2)
df_eNodeb['下行PRB利用率']=round(df_eNodeb['下行PRB利用率'],2)
df_eNodeb['下行最大激活用户数']=round(df_eNodeb['下行最大激活用户数'],2)
df_eNodeb['下行用户面时延']=round(df_eNodeb['下行用户面时延'],0)
df_eNodeb['用户体验速率']=round(df_eNodeb['用户体验速率'],2)
df_eNodeb1['下行PRB利用率']=round(df_eNodeb1['下行PRB利用率'],2)
df_eNodeb1['下行最大激活用户数']=round(df_eNodeb1['下行最大激活用户数'],2)
df_eNodeb1['下行用户面时延']=round(df_eNodeb1['下行用户面时延'],0)
df_eNodeb1['用户体验速率']=round(df_eNodeb1['用户体验速率'],2)
df_qindang_county=df_qindang_county[['网元', '小区号', '小区名称','区域', '频段', '区县','支局','上行流量(GB)', '下行流量(GB)', '总流量(GB)','忙时RRC最大连接用户数', '下行PRB利用率', '下行最大激活用户数', '下行用户面时延',
'用户体验速率']]
df_eNodeb=df_eNodeb[['网元','区县', '中文站名', '区域', '频段', '支局','扇区数','上行流量(GB)', '下行流量(GB)','总流量(GB)', '忙时RRC最大连接用户数','下行最大激活用户数','下行用户面时延', '用户体验速率','下行PRB利用率']]
df_eNodeb1=df_eNodeb1[['网元','区县', '中文站名', '区域', '频段', '支局','扇区数','上行流量(GB)','下行流量(GB)','总流量(GB)', '忙时RRC最大连接用户数', '下行最大激活用户数','下行PRB利用率','下行用户面时延','用户体验速率','下行PRB利用率','价值']]
# =============================================================================
# df_eNodeb1.rename(columns={'上行流量(GB)_上周':'上行流量(TB)_上周',
# '上行流量(GB)_本周':'上行流量(TB)_本周',
# '下行流量(GB)_上周':'下行流量(TB)_上周',
# '下行流量(GB)_本周':'下行流量(TB)_本周',
# '总流量(GB)_上周':'总流量(TB)_上周',
# '总流量(GB)_本周':'总流量(TB)_本周'},inplace =True)
# =============================================================================
with pd.ExcelWriter(path_out+'4G话务周报.xlsx') as writer:
workbook = writer.book
col_fmt = workbook.add_format({'bold': True, # 字体加粗
'font_size': 10, # 字体大小
'font_name': u'微软雅黑', # 字体
'num_format': '0.00', # 数字格式
'bg_color': '#E0FFFF', # 单元格背景色
'valign': 'vcenter', # 垂直对齐方式
'align': 'center', # 水平对齐方式
'top' : 2, # 上边框,后面参数是线条宽度
'left' : 2, # 左边框
'right' : 2, # 右边框
'bottom' : 2, # 底边框
'border' : 1 , # 边框
'text_wrap': True}) # 自动换行,可在文本中加 '\n'来控制换行的位置
col1_fmt = workbook.add_format({'bold': True, # 字体加粗
'font_size': 10, # 字体大小
'font_name': u'微软雅黑', # 字体
'num_format': '0.00', # 数字格式
'bg_color': '#CDCDC1', # 单元格背景色
'valign': 'vcenter', # 垂直对齐方式
'align': 'center', # 水平对齐方式
'top' : 2, # 上边框,后面参数是线条宽度
'left' : 2, # 左边框
'right' : 2, # 右边框
'bottom' : 2, # 底边框
'border' : 1 , # 边框
'text_wrap': True}) # 自动换行,可在文本中加 '\n'来控制换行的位置
col2_fmt = workbook.add_format({'bold': True, # 字体加粗
'font_size': 10, # 字体大小
'font_name': u'微软雅黑', # 字体
'num_format': '0.00', # 数字格式
'bg_color': '#FFC125', # 单元格背景色
'valign': 'vcenter', # 垂直对齐方式
'align': 'center', # 水平对齐方式
'top' : 2, # 上边框,后面参数是线条宽度
'left' : 2, # 左边框
'right' : 2, # 右边框
'bottom' : 2, # 底边框
'border' : 1 , # 边框
'text_wrap': True}) # 自动换行,可在文本中加 '\n'来控制换行的位置
col3_fmt = workbook.add_format({'bold': True, # 字体加粗
'font_size': 10, # 字体大小
'font_name': u'微软雅黑', # 字体
'num_format': '0.00', # 数字格式
'bg_color': '#F4A460', # 单元格背景色
'valign': 'vcenter', # 垂直对齐方式
'align': 'center', # 水平对齐方式
'top' : 2, # 上边框,后面参数是线条宽度
'left' : 2, # 左边框
'right' : 2, # 右边框
'bottom' : 2, # 底边框
'border' : 1 , # 边框
'text_wrap': True}) # 自动换行,可在文本中加 '\n'来控制换行的位置
noraml_fmt = workbook.add_format({"font_name": u"微软雅黑"})
percent_fmt = workbook.add_format({'num_format': '0.00%'})
header_fmt = workbook.add_format({'bold': True,
'font_name': u'微软雅黑',
'font_size': 16, # 字体大小
'align': 'center', # 水平对齐方式
'border' : 2 , # 边框
'font_color': 'red',
'valign': 'vcenter'}) #设置标题格式
title_fmt = workbook.add_format({'bold': True,
'font_name': u'微软雅黑',
'align': 'center', # 水平对齐方式
'border' : 2 , # 边框
'font_color': 'blue',
'valign': 'vcenter'}) #设置标题格式
red_fmt = workbook.add_format({'bg_color': '#FFE4E1',
'num_format': '0.00%'})
border_format = workbook.add_format({'border' : 1 })
# =============================================================================
#
# =============================================================================
book = writer.book # 将图片插入到excel表格中
sheet = book.add_worksheet('各区县用户数及流量')
df_all_county['下行最大激活用户数_本周']=df_all_county['下行最大激活用户数_本周'].astype(int)
df_all_county['下行最大激活用户数_上周']=df_all_county['下行最大激活用户数_上周'].astype(int)
# =============================================================================
#
# =============================================================================
df_all_county.to_excel(writer,
sheet_name=u'两周数据对比',
encoding='utf8',
header=False,
index=False,
startcol=0,
startrow=3)
worksheet1 = writer.sheets[u'两周数据对比']
for col_num, value in enumerate(df_all_county.columns.values):
worksheet1.write(2, col_num, value, col_fmt)
worksheet1.merge_range('A1:U1', u'两周数据对比', header_fmt)
worksheet1.merge_range('B2:G2', u'流量', col_fmt)
worksheet1.merge_range('H2:I2', u'prb利用率', col1_fmt)
worksheet1.merge_range('J2:M2', u'用户数', col2_fmt)
worksheet1.merge_range('N2:O2', u'用户面时间延时', col3_fmt)
worksheet1.merge_range('P2:S2', u'基站数量', col_fmt)
worksheet1.merge_range('T2:U2', u'体验速率', col1_fmt)
l_end = len(df_all_county) + 3
worksheet1.conditional_format(
'A3:G%d' % l_end,
{'type': 'no_blanks', 'format': noraml_fmt}) # 所有非空单元格设置为 noraml_fmt
worksheet1.conditional_format(
'J3:U%d' % l_end,
{'type': 'no_blanks', 'format': noraml_fmt}) # 所有非空单元格设置为 noraml_fmt
worksheet1.conditional_format('A4:U%d' % l_end, {'type': 'no_blanks', 'format': border_format})
# =============================================================================
#
# =============================================================================
df_qindang_county['下行最大激活用户数']=df_qindang_county['下行最大激活用户数'].astype(int)
df_enodeb_name1=df_enodeb_name
df_enodeb_name1['中文小区名']=df_enodeb_name1['小区号']+'_'+df_enodeb_name1['中文站名']
df_enodeb_name1=df_enodeb_name1[['小区号','中文小区名']]
df_qindang_county=pd.merge(df_qindang_county,df_enodeb_name1,how ='left',on = '小区号' )
df_qindang_county=df_qindang_county[['网元', '小区号', '中文小区名','区域', '频段', '区县','支局','上行流量(GB)', '下行流量(GB)', '总流量(GB)','忙时RRC最大连接用户数', '下行PRB利用率', '下行最大激活用户数', '下行用户面时延',
'用户体验速率']]
df_qindang_county.to_excel(writer,
sheet_name=u'小区清单',
encoding='utf8',
header=False,
index=False,
startcol=0,
startrow=3)
worksheet2 = writer.sheets[u'小区清单']
for col_num, value in enumerate(df_qindang_county.columns.values):
worksheet2.write(2, col_num, value, col_fmt)
worksheet2.merge_range('A1:O1', u'全部小区数据', header_fmt)
worksheet2.merge_range('A2:G2', u'小区信息', col_fmt)
worksheet2.merge_range('H2:O2', u'话务情况', col1_fmt)
l_end = len(df_qindang_county) + 3
worksheet2.conditional_format(
'A3:K%d' % l_end,
{'type': 'no_blanks', 'format': noraml_fmt}) # 所有非空单元格设置为 noraml_fmt
worksheet2.conditional_format('A4:P%d' % l_end, {'type': 'no_blanks', 'format': border_format})
worksheet2.set_column('B:B', 11)
worksheet2.set_column('C:C', 34.25)
# =============================================================================
#
# =============================================================================
df_eNodeb['下行最大激活用户数']=df_eNodeb['下行最大激活用户数'].astype(int)
df_eNodeb.to_excel(writer,
sheet_name=u'物理站址请单',
encoding='utf8',
header=False,
index=False,
startcol=0,
startrow=3)
worksheet3 = writer.sheets[u'物理站址请单']
for col_num, value in enumerate(df_eNodeb.columns.values):
worksheet3.write(2, col_num, value, col_fmt)
worksheet3.merge_range('A1:O1', u'全部物理站址信息', header_fmt)
worksheet3.merge_range('A2:F2', u'物理站址信息', col_fmt)
worksheet3.merge_range('G2:O2', u'话务情况', col1_fmt)
l_end = len(df_qindang_county) + 3
worksheet3.conditional_format(
'A3:M%d' % l_end,
{'type': 'no_blanks', 'format': noraml_fmt}) # 所有非空单元格设置为 noraml_fmt
worksheet3.conditional_format('A4:P%d' % l_end, {'type': 'no_blanks', 'format': border_format})
worksheet3.set_column('C:C', 51.5)
# =============================================================================
#
# =============================================================================
#a=df_eNodeb1.columns
#print(a)
df_eNodeb1['下行最大激活用户数']=df_eNodeb1['下行最大激活用户数'].astype(int)
df_eNodeb1.to_excel(writer,
sheet_name=u'L800M基站价值清单',
encoding='utf8',
header=False,
index=False,
startcol=0,
startrow=3)
worksheet4 = writer.sheets[u'L800M基站价值清单']
for col_num, value in enumerate(df_eNodeb1.columns.values):
worksheet4.write(2, col_num, value, col_fmt)
worksheet4.merge_range('A1:O1', u'L800M基站价值清单', header_fmt)
worksheet4.merge_range('A2:F2', u'L800M基站信息', col_fmt)
worksheet4.merge_range('G2:O2', u'话务情况', col1_fmt)
l_end = len(df_qindang_county) + 3
worksheet4.conditional_format(
'A3:K%d' % l_end,
{'type': 'no_blanks', 'format': noraml_fmt}) # 所有非空单元格设置为 noraml_fmt
worksheet4.conditional_format('A4:P%d' % l_end, {'type': 'no_blanks', 'format': border_format})
worksheet4.set_column('B:B', 32.88)
worksheet4.set_column('O:O', 12.38)
# =============================================================================
#
# =============================================================================
df_jz2.to_excel(writer,'L800基站价值汇总',index=False)
df_jz2.to_excel(writer,
sheet_name=u'L800基站价值汇总',
encoding='utf8',
header=False,
index=False,
startcol=0,
startrow=2)
worksheet5 = writer.sheets[u'L800基站价值汇总']
for col_num, value in enumerate(df_jz2.columns.values):
worksheet5.write(1, col_num, value, col_fmt)
worksheet5.merge_range('A1:L1', u'L800M基站价值', header_fmt)
l_end = len(df_qindang_county) + 2
worksheet5.conditional_format(
'A2:B%d' % l_end,
{'type': 'no_blanks', 'format': noraml_fmt}) # 所有非空单元格设置为 noraml_fmt
worksheet5.conditional_format(
'C3:C%d'% l_end,
{'type': 'no_blanks', 'format': percent_fmt}) # 话务量环比变化,设置为 percent_fmt
worksheet5.conditional_format(
'E3:E%d'% l_end,
{'type': 'no_blanks', 'format': percent_fmt}) # 话务量环比变化,设置为 percent_fmt
worksheet5.conditional_format(
'G3:G%d'% l_end,
{'type': 'no_blanks', 'format': percent_fmt}) # 话务量环比变化,设置为 percent_fmt
worksheet5.conditional_format(
'I3:I%d'% l_end,
{'type': 'no_blanks', 'format': percent_fmt}) # 话务量环比变化,设置为 percent_fmt
worksheet5.conditional_format(
'K3:K%d'% l_end,
{'type': 'no_blanks', 'format': percent_fmt}) # 话务量环比变化,设置为 percent_fmt
worksheet5.conditional_format('A3:L%d' % l_end, {'type': 'no_blanks', 'format': border_format})
huatu2('4G话务周报.xlsx','各区县用户数及流量')
with pd.ExcelWriter(path_out+'L800基站价值.xlsx') as writer:
workbook = writer.book
col_fmt = workbook.add_format({'bold': True, # 字体加粗
'font_size': 10, # 字体大小
'font_name': u'微软雅黑', # 字体
'num_format': '0.00', # 数字格式
'bg_color': '#E0FFFF', # 单元格背景色
'valign': 'vcenter', # 垂直对齐方式
'align': 'center', # 水平对齐方式
'top' : 2, # 上边框,后面参数是线条宽度
'left' : 2, # 左边框
'right' : 2, # 右边框
'bottom' : 2, # 底边框
'border' : 1 , # 边框
'text_wrap': True}) # 自动换行,可在文本中加 '\n'来控制换行的位置
col1_fmt = workbook.add_format({'bold': True, # 字体加粗
'font_size': 10, # 字体大小
'font_name': u'微软雅黑', # 字体
'num_format': '0.00', # 数字格式
'bg_color': '#CDCDC1', # 单元格背景色
'valign': 'vcenter', # 垂直对齐方式
'align': 'center', # 水平对齐方式
'top' : 2, # 上边框,后面参数是线条宽度
'left' : 2, # 左边框
'right' : 2, # 右边框
'bottom' : 2, # 底边框
'border' : 1 , # 边框
'text_wrap': True}) # 自动换行,可在文本中加 '\n'来控制换行的位置
col2_fmt = workbook.add_format({'bold': True, # 字体加粗
'font_size': 10, # 字体大小
'font_name': u'微软雅黑', # 字体
'num_format': '0.00', # 数字格式
'bg_color': '#FFC125', # 单元格背景色
'valign': 'vcenter', # 垂直对齐方式
'align': 'center', # 水平对齐方式
'top' : 2, # 上边框,后面参数是线条宽度
'left' : 2, # 左边框
'right' : 2, # 右边框
'bottom' : 2, # 底边框
'border' : 1 , # 边框
'text_wrap': True}) # 自动换行,可在文本中加 '\n'来控制换行的位置
col3_fmt = workbook.add_format({'bold': True, # 字体加粗
'font_size': 10, # 字体大小
'font_name': u'微软雅黑', # 字体
'num_format': '0.00', # 数字格式
'bg_color': '#F4A460', # 单元格背景色
'valign': 'vcenter', # 垂直对齐方式
'align': 'center', # 水平对齐方式
'top' : 2, # 上边框,后面参数是线条宽度
'left' : 2, # 左边框
'right' : 2, # 右边框
'bottom' : 2, # 底边框
'border' : 1 , # 边框
'text_wrap': True}) # 自动换行,可在文本中加 '\n'来控制换行的位置
noraml_fmt = workbook.add_format({"font_name": u"微软雅黑"})
percent_fmt = workbook.add_format({'num_format': '0.00%'})
header_fmt = workbook.add_format({'bold': True,
'font_name': u'微软雅黑',
'font_size': 16, # 字体大小
'align': 'center', # 水平对齐方式
'border' : 2 , # 边框
'font_color': 'red',
'valign': 'vcenter'}) #设置标题格式
title_fmt = workbook.add_format({'bold': True,
'font_name': u'微软雅黑',
'align': 'center', # 水平对齐方式
'border' : 2 , # 边框
'font_color': 'blue',
'valign': 'vcenter'}) #设置标题格式
red_fmt = workbook.add_format({'bg_color': '#FFE4E1',
'num_format': '0.00%'})
border_format = workbook.add_format({'border' : 1 })
# =============================================================================
#
# =============================================================================
df_eNodeb1.to_excel(writer,
sheet_name=u'L800M基站价值清单',
encoding='utf8',
header=False,
index=False,
startcol=0,
startrow=3)
worksheet4 = writer.sheets[u'L800M基站价值清单']
for col_num, value in enumerate(df_eNodeb1.columns.values):
worksheet4.write(2, col_num, value, col_fmt)
worksheet4.merge_range('A1:O1', u'L800M基站价值清单', header_fmt)
worksheet4.merge_range('A2:F2', u'L800M基站信息', col_fmt)
worksheet4.merge_range('G2:O2', u'话务情况', col1_fmt)
l_end = len(df_qindang_county) + 3
worksheet4.conditional_format(
'A3:K%d' % l_end,
{'type': 'no_blanks', 'format': noraml_fmt}) # 所有非空单元格设置为 noraml_fmt
worksheet4.conditional_format('A4:P%d' % l_end, {'type': 'no_blanks', 'format': border_format})
worksheet4.set_column('B:B', 32.88)
worksheet4.set_column('O:O', 12.38)
# =============================================================================
#
# =============================================================================
df_jz2.to_excel(writer,
sheet_name=u'L800基站价值汇总',
encoding='utf8',
header=False,
index=False,
startcol=0,
startrow=2)
worksheet5 = writer.sheets[u'L800基站价值汇总']
for col_num, value in enumerate(df_jz2.columns.values):
worksheet5.write(1, col_num, value, col_fmt)
worksheet5.merge_range('A1:L1', u'L800M基站价值', header_fmt)
l_end = len(df_qindang_county) + 2
worksheet5.conditional_format(
'A2:B%d' % l_end,
{'type': 'no_blanks', 'format': noraml_fmt}) # 所有非空单元格设置为 noraml_fmt
worksheet5.conditional_format(
'C3:C%d'% l_end,
{'type': 'no_blanks', 'format': percent_fmt}) # 话务量环比变化,设置为 percent_fmt
worksheet5.conditional_format(
'E3:E%d'% l_end,
{'type': 'no_blanks', 'format': percent_fmt}) # 话务量环比变化,设置为 percent_fmt
worksheet5.conditional_format(
'G3:G%d'% l_end,
{'type': 'no_blanks', 'format': percent_fmt}) # 话务量环比变化,设置为 percent_fmt
worksheet5.conditional_format(
'I3:I%d'% l_end,
{'type': 'no_blanks', 'format': percent_fmt}) # 话务量环比变化,设置为 percent_fmt
worksheet5.conditional_format(
'K3:K%d'% l_end,
{'type': 'no_blanks', 'format': percent_fmt}) # 话务量环比变化,设置为 percent_fmt
worksheet5.conditional_format('A3:L%d' % l_end, {'type': 'no_blanks', 'format': border_format})
# =============================================================================
# 写docx
# =============================================================================
document = Document()
# 定义文档默认字体style_1为楷体
document.styles['Normal'].font.name = u'华文楷体'
document.styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'), u'华文楷体')
document.styles['Normal'].font.size = Pt(14)
style_1 = document.styles['Normal']
# 添加文档标题 等级0
title = document.add_heading('', level=0).add_run('4G话务量周报')
title.font.name = u'华文楷体'
title._element.rPr.rFonts.set(qn('w:eastAsia'), u'华文楷体')
title.font.size = Pt(25)
# 添加第一段标题
head1 = document.add_heading('', level=1).add_run('基本信息')
head1.font.name = u'华文楷体'
head1._element.rPr.rFonts.set(qn('w:eastAsia'), u'华文楷体')
head1.font.size = Pt(20)
# 添加第一段的1小节标题
head2 = document.add_heading('', level=2).add_run('1.1 基站数量')
head2.font.name = u'华文楷体'
head2._element.rPr.rFonts.set(qn('w:eastAsia'), u'华文楷体')
head2.font.size = Pt(16)
#添加图片
document.add_picture('./pic/基站数量' + ".png", width=Inches(6))
# 添加基站数量描述
document.add_paragraph('本周基站数{jzs_rate}个,本周物理站址数{jzs_level}个。'.format(
jzs_rate=jzsl(df_all_county.loc[9,'基站数_本周'],df_all_county.loc[9,'基站数_上周']),
jzs_level = int(df_all_county.loc[9,'基站数_本周'])),
style=style_1)
# 添加第一段的2小节标题
head2 = document.add_heading('', level=2).add_run('1.2 忙时RRC用户数')
head2.font.name = u'华文楷体'
head2._element.rPr.rFonts.set(qn('w:eastAsia'), u'华文楷体')
head2.font.size = Pt(16)
#添加图片
document.add_picture('./pic/忙时RRC用户数' + ".png", width=Inches(6))
document.add_paragraph('本周忙时RRC最大连接用户数{rrc_rate}人,本周忙时RRC最大连接用户数{rrc_level}人。'.format(
rrc_rate=jzsl(df_all_county.loc[9,'忙时RRC最大连接用户数_本周'],df_all_county.loc[9,'忙时RRC最大连接用户数_上周']),
rrc_level = int(df_all_county.loc[9,'忙时RRC最大连接用户数_本周'])),
style=style_1)
# 添加第一段的3小节标题
head2 = document.add_heading('', level=2).add_run('1.3 总流量(TB)')
head2.font.name = u'华文楷体'
head2._element.rPr.rFonts.set(qn('w:eastAsia'), u'华文楷体')
head2.font.size = Pt(16)
#添加图片
document.add_picture('./pic/总流量(TB)' + ".png", width=Inches(6))
document.add_paragraph('本周总流量{ll_rate}(TB),本周流量为{ll_level}(TB)。'.format(
ll_rate=jzsl(df_all_county.loc[9,'总流量(TB)_本周'],df_all_county.loc[9,'总流量(TB)_上周']),
ll_level = df_all_county.loc[9,'总流量(TB)_本周']),
style=style_1)
# 添加第一段的4小节标题
head2 = document.add_heading('', level=2).add_run('1.4 下行PRB利用率(%)')
head2.font.name = u'华文楷体'
head2._element.rPr.rFonts.set(qn('w:eastAsia'), u'华文楷体')
head2.font.size = Pt(16)
#添加图片
document.add_picture('./pic/下行PRB利用率(%)' + ".png", width=Inches(6))
document.add_paragraph('本周下行PRB利用率{prb_rate}%,本周下行PRB利用率为{prb_level}%。'.format(
prb_rate=jzsl(df_all_county.loc[9,'下行PRB利用率_本周'],df_all_county.loc[9,'下行PRB利用率_上周']),
prb_level = round(df_all_county.loc[9,'下行PRB利用率_本周'],2)),
style=style_1)
# 添加第一段的5小节标题
head2 = document.add_heading('', level=2).add_run('1.5 用户体验速率(Mbps)')
head2.font.name = u'华文楷体'
head2._element.rPr.rFonts.set(qn('w:eastAsia'), u'华文楷体')
head2.font.size = Pt(16)
#添加图片
document.add_picture('./pic/用户体验速率(Mbps)' + ".png", width=Inches(6))
document.add_paragraph('本周用户体验速率{ty_rate}(Mbps),本周用户体验速率为{ty_level}(Mbps)。'.format(
ty_rate=jzsl(df_all_county.loc[9,'用户体验速率_本周'],df_all_county.loc[9,'用户体验速率_上周']),
ty_level = round(df_all_county.loc[9,'用户体验速率_本周'],2)),
style=style_1)
# 添加第一段的6小节标题
head2 = document.add_heading('', level=2).add_run('1.6 下行最大激活用户数')
head2.font.name = u'华文楷体'
head2._element.rPr.rFonts.set(qn('w:eastAsia'), u'华文楷体')
head2.font.size = Pt(16)
#添加图片
document.add_picture('./pic/下行最大激活用户数' + ".png", width=Inches(6))
document.add_paragraph('本周下行最大激活用户数{AT_rate}人,本周下行最大激活用户数为{AT_level}人。'.format(
AT_rate=jzsl(df_all_county.loc[9,'下行最大激活用户数_本周'],df_all_county.loc[9,'下行最大激活用户数_上周']),
AT_level = int(df_all_county.loc[9,'下行最大激活用户数_本周'])),
style=style_1)
# 添加第一段的7小节标题
head2 = document.add_heading('', level=2).add_run('1.7 下行用户面时延')
head2.font.name = u'华文楷体'
head2._element.rPr.rFonts.set(qn('w:eastAsia'), u'华文楷体')
head2.font.size = Pt(16)
#添加图片
document.add_picture('./pic/下行用户面时延(ms)' + ".png", width=Inches(6))
document.add_paragraph('本周下行用户面时延{sy_rate}(ms),本周下行用户面时延为{sy_level}(ms)。'.format(
sy_rate=jzsl(df_all_county.loc[9,'下行用户面时延_本周'],df_all_county.loc[9,'下行用户面时延_上周']),
sy_level = int(df_all_county.loc[9,'下行用户面时延_本周'])),
style=style_1)
# 添加第一段标题
# =============================================================================
# head1 = document.add_heading('', level=1).add_run('二、基站价值')
# head1.font.name = u'华文楷体'
# head1._element.rPr.rFonts.set(qn('w:eastAsia'), u'华文楷体')
# head1.font.size = Pt(20)
# df2=df_jzjz
# tb=document.add_table(rows=len(df2.index),cols=len(df2.columns))
# tb.add_row()
# for i in range(len(df2.columns)):
# tb.cell(0,i).text=df2.columns[i]#添加表头
# for row in range(1,len(df2.index)+1):
# for col in range(len(df2.columns)):
# tb.cell(row,col)
#
# =============================================================================
document.add_page_break()
document.save(path_out+'4G话务周报.docx')
print('喵喵已经写好4G话务周报.docx')
print('喵喵已经工作完了')
with pd.ExcelWriter(path_out+'小区数据入库.xlsx') as writer:
workbook = writer.book
a=getWeekDaysByNum(-1,0)
a=a.get(-1)
df_qindang_county_ruku=df_qindang_county.copy()
df_qindang_county_ruku['开始时间']=str(a[0])
df_qindang_county_ruku['接收时间']=str(a[1])
df_qindang_county_ruku['key'] = df_qindang_county_ruku['小区号'].map(lambda x :x+"_"+str(a[0])+"_"+str(a[1]))
df_qindang_county_ruku.to_excel(writer,sheet_name=u'小区清单',index=False,encoding='utf8')
worksheet2 = writer.sheets[u'小区清单']
with pd.ExcelWriter(path_out+'物理站址数据入库.xlsx') as writer:
workbook = writer.book
a=getWeekDaysByNum(-1,0)
a=a.get(-1)
df_eNodeb_ruku=df_eNodeb.copy()
df_eNodeb_ruku['开始时间']=str(a[0])
df_eNodeb_ruku['结束时间']=str(a[1])
df_eNodeb_ruku['key'] = df_eNodeb_ruku['网元'].astype(str)+'_'+df_eNodeb_ruku['中文站名']+"_"+df_eNodeb_ruku['频段']
df_eNodeb_ruku['key'] = df_eNodeb_ruku['key'].map(lambda x :x+"_"+str(a[0])+"_"+str(a[1]))
df_eNodeb_ruku.to_excel(writer,sheet_name=u'物理站址清单',index=False,encoding='utf8')
with pd.ExcelWriter(path_out+'检查.xlsx') as writer: # 输出到excel检查
df_zongbiao.to_excel(writer,'物理站址')
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化