|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 zhuhq28 于 2021-2-6 20:35 编辑
python程序遇到下面的问题:
IndexError: index 2 is out of bounds for axis 0 with size
附件是涉及的excelwen文件
from openpyxl import load_workbook
import pandas as pd
from openpyxl import styles
IndexError: index 2 is out of bounds for axis 0 with size 0
gc = pd.read_excel(r"D:\desktop\gccj.xlsx",sheet_name = 'Report')
wb = load_workbook(r"D:\desktop\gccj.xlsx")
ws = wb.create_sheet("统计",0)
def get_cell_type(x):
if '联通共享' in x["用户标识"] and 'DRS' in x["用户标识"]:
return '联通室分'
elif '联通共享' in x["用户标识"] and 'DRS' not in x["用户标识"]:
return '联通宏站'
elif '联通共享' not in x["用户标识"] and 'DRS' in x["用户标识"]:
return '电信室分'
else:
return "电信宏站"
gc.loc[:,'cell_type'] = gc.apply(get_cell_type,axis=1)
ws.column_dimensions['A'].width = 14.0
ws.column_dimensions['B'].width = 14.0
ws.column_dimensions['C'].width = 14.0
ws.column_dimensions['D'].width = 14.0
ws.column_dimensions['E'].width = 14.0
ws['A1'] = '电信基站总数'
ws['B1'] = '联通基站总数'
ws['C1'] = '联通小区总数'
ws['D1'] = '联通宏站小区数'
ws['E1'] = '联通室分小区数'
if gc["cell_type"].value_counts()[2] == 64 :
ws["A2"] = gc["cell_type"].value_counts()[1] / 3 +19
ws["B2"] = gc["cell_type"].value_counts()[0] / 3 +19
ws["C2"] = gc["cell_type"].value_counts()[0] + gc["cell_type"].value_counts()[3]
ws["D2"] = gc["cell_type"].value_counts()[0]
ws["E2"] = gc["cell_type"].value_counts()[3]
else:
ws['B2'] = '室分小区数变化,重新计算'
ws['C2'] = '室分小区数变化,重新计算'
ws['D2'] = '室分小区数变化,重新计算'
ws['E2']= '室分小区数变化,重新计算'
wb.save(r"D:\desktop\gccj.xlsx")
|
|