#!/usr/bin/env python3 # -*- coding: utf-8 -*- ' a test module ' __author__ = 'Wu Zongshuai' import pandas as pd from sqlalchemy import create_engine import os os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8' engine = create_engine("oracle://zzwyjjl:Omc5_012@10.87.72.50/OSS") writer = pd.ExcelWriter(r'D:\邻区.xlsx') sql = """ SELECT BTS.CO_OBJECT_INSTANCE|| '-'||LNADJ.LNADJ_ADJ_ENB_ID 正向邻区对 ,LNADJ.LNADJ_ADJ_ENB_ID|| '-'||BTS.CO_OBJECT_INSTANCE 反向邻区对 ,BTS.CO_OBJECT_INSTANCE "源enb_id" ,ADJ.CO_OBJECT_INSTANCE "正向编号LNADJ_ID" ,decode(LNADJ.LNADJ_CPIAC_7,0,'oamControlled ',1,'enbControlled') "cPlaneIpAddrCtrl" ,LNADJ.LNADJ_C_PLANE_IP_ADDR "cPlaneIpAddr" ,LNADJ.LNADJ_ADJ_ENB_ID "邻adjEnbId" ,decode(LNADJ.LNADJ_RBRRPE_8,0,'false ',1,'true') "rlfBasedRCRsupported" ,decode(LNADJ.LNADJ_X_2_LINK_STAT,0,'unavailable ',1,'available') "x2LinkStatus" ,decode(s.EXENBF_MACRO_ENB_ID,null,'内部','外部') "adj_type" FROM C_LTE_LNADJ LNADJ ,CTP_COMMON_OBJECTS ADJ ,CTP_COMMON_OBJECTS BTS ,(select c_vex_exenbf.EXENBF_MACRO_ENB_ID from c_vex_exenbf where c_vex_exenbf.conf_id='1') s WHERE LNADJ.OBJ_GID=ADJ.CO_GID AND ADJ.CO_PARENT_GID=BTS.CO_GID and lnadj_adj_enb_id =s.EXENBF_MACRO_ENB_ID(+) AND LNADJ.CONF_ID=1 AND ADJ.CO_STATE='0' --and BTS.CO_OBJECT_INSTANCE in ('740798') --and LNADJ.LNADJ_ADJ_ENB_ID in ('46999') order by BTS.CO_OBJECT_INSTANCE asc ,LNADJ.LNADJ_ADJ_ENB_ID asc """ df = pd.read_sql(sql, engine) print(df) df.to_excel(writer, sheet_name='omc5', index=False) writer.save()
以下是错误信息:
Traceback (most recent call last):
File "D:/pypypy/练习/临时练习.py", line 45, in <module>
df.to_excel(writer, sheet_name='omc5', index=False)
File "C:\Users\wuzongshuai\AppData\Roaming\Python\Python37\site-packages\pandas\core\generic.py", line 2127, in to_excel
engine=engine)
File "C:\Users\wuzongshuai\AppData\Roaming\Python\Python37\site-packages\pandas\io\formats\excel.py", line 662, in write
freeze_panes=freeze_panes)
File "C:\Users\wuzongshuai\AppData\Roaming\Python\Python37\site-packages\pandas\io\excel.py", line 1605, in write_cells
xcell.value, fmt = self._value_with_fmt(cell.val)
File "C:\Users\wuzongshuai\AppData\Roaming\Python\Python37\site-packages\openpyxl\cell\cell.py", line 252, in value
self._bind_value(value)
File "C:\Users\wuzongshuai\AppData\Roaming\Python\Python37\site-packages\openpyxl\cell\cell.py", line 218, in _bind_value
raise ValueError("Cannot convert {0!r} to Excel".format(value))
ValueError: Cannot convert '\u6b63\u5411\u90bb\u533a\u5bf9' to Excel