找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 3229|回复: 1

[求助] 使用xlwt包出现报错row index , not allowed by .xls format

3

主题

7

帖子

7

积分

贫民

积分
7
gumiaoyan 发表于 2017-10-17 13:28:15 | 显示全部楼层 |阅读模式
求教,在使用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')        


回复

使用道具 举报

3

主题

7

帖子

7

积分

贫民

积分
7
gumiaoyan  楼主| 发表于 2017-10-17 13:41:57 | 显示全部楼层
应该讲locations[item1]的位置换为item1
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表