|
求教,在使用xlwt包的时候总是出现row index was '安徽省安庆市 ', not allowed by .xls format这样的提示信息,数据量为一万多条,不存在超出sheet表大小的问题,不知道因为什么原因。
代码如下:
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 17 09:28:38 2017
@author: user
"""
import xlrd
import xlwt
data = xlrd.open_workbook('d:/Pythonfiles/ip2.xls')
data1 = xlwt.Workbook(encoding = 'utf-8')
table = data.sheet_by_index(0)
table1 = data1.add_sheet('processed')
provices = ['北京','天津','上海', '重庆', '新疆', '宁夏', '西藏', '广西', '内蒙古',
'河北', '山西', '辽宁', '吉林', '黑龙江', '江苏', '浙江', '安徽', '福建',
'江西', '山东', '河南', '湖北', '湖南', '广东', '海南', '四川', '贵州',
'云南', '陕西', '甘肃', '青海', '台湾','香港' ,'澳门']
locations = table.col_values(1)
for item1 in range(len(locations)):
for item2 in range(len(provices)):
if provices[item2] in locations[item1]:
table1.write(locations[item1],3,provices[item2])
break
data1.save('d:/Pythonfiles/ip3.xls')
|
|