IndexError: index 2 is out of bounds for axis 0 with size 0
本帖最后由 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() == 64 :
ws["A2"] = gc["cell_type"].value_counts() / 3 +19
ws["B2"] = gc["cell_type"].value_counts() / 3 +19
ws["C2"] = gc["cell_type"].value_counts() + gc["cell_type"].value_counts()
ws["D2"] = gc["cell_type"].value_counts()
ws["E2"] = gc["cell_type"].value_counts()
else:
ws['B2'] = '室分小区数变化,重新计算'
ws['C2'] = '室分小区数变化,重新计算'
ws['D2'] = '室分小区数变化,重新计算'
ws['E2']= '室分小区数变化,重新计算'
wb.save(r"D:\desktop\gccj.xlsx")
这涉及到未知源文件,谁能回答 wp231957 发表于 2021-2-6 20:20
这涉及到未知源文件,谁能回答
附件上传了 是涉及的EXCEL文件
页:
[1]