ValueError: row index was 65536, not allowed by .xls format
报错:ValueError: row index was 65536, not allowed by .xls format
读取.xls文件正常,在写.xls文件,pd.to_excel()时候会报错
原因:写入的文件行数大于65536
Pandas 读取 Excel 文件的引擎是 xlrd ,xlrd 虽然同时支持 .xlsx 和 .xls 两种文件格式,但是在源码文件 xlrd/sheet.py 中限制了读取的 Excel 文件行数必须小于 65536,列数必须小于 256。
xlrd和xlwt处理的是xls文件,单个sheet最大行数是65535,如果有更大需要的,建议使用openpyxl函数,最大行数达到1048576。
如果数据量超过65535就会遇到:ValueError: row index was 65536, not allowed by .xls format
解决:
方法1: 直接使用openpyxl
import openpyxl def readExel():
filename = r'D:\test.xlsx'
inwb = openpyxl.load_workbook(filename) # 读文件
sheetnames = inwb.get_sheet_names() # 获取读文件中所有的sheet,通过名字的方式
ws = inwb.get_sheet_by_name(sheetnames[0]) # 获取第一个sheet内容 # 获取sheet的最大行数和列数
rows = ws.max_row
cols = ws.max_column
for r in range(1,rows):
for c in range(1,cols):
print(ws.cell(r,c).value)
if r==10:
break def writeExcel():
outwb = openpyxl.Workbook() # 打开一个将写的文件
outws = outwb.create_sheet(index=0) # 在将写的文件创建sheet
for row in range(1,70000):
for col in range(1,4):
outws.cell(row, col).value = row*2 # 写文件
print(row)
saveExcel = "D:\\test2.xlsx"
outwb.save(saveExcel) # 一定要记得保存
方法2:Pandas 的 read_excel 方法中,有 engine 字段,可以指定所使用的处理 Excel 文件的引擎,填入 openpyxl ,再读取文件就可以了。
import pandas as pd df = pd.read_excel(‘./data.xlsx’, engine=’openpyxl’) pd.write( ,engine=’openpyxl’)
ValueError: row index was 65536, not allowed by .xls format的更多相关文章
- [已解决]ValueError: row index was 65536, not allowed by .xls format
报错: ValueError: row index was 65536, not allowed by .xls format 解决方案: xlrd和xlwt处理的是xls文件,单个sheet最大行数 ...
- jQuery EasyUI, datagrid, treegrid formatter 参数比较 row index
如题: datagrid中,见官方文档: formatter function The cell formatter function, take three parameter:value: the ...
- EasyUI datagrid 删除的时候无法正确找到重复记录row index的问题
EasyUI datagrid 删除的时候无法正确找到重复记录row index的问题: 如果无法正确找到重复记录的row index,就需要进行注意添加的时候所进行的 操作:如果添加的时候就是添加的 ...
- 作用域插槽 向父组件传递 <template slot-scope="{ row, index }" slot="dateNo">
作用域插槽 向父组件传递 <template slot-scope="{ row, index }" slot="dateNo"> slotTes ...
- pandas里面过滤列出现ValueError: cannot index with vector containing NA / NaN values错误的解决方法(转)
###df_18的字段fuek是否包含 / df_18[df_18['fuel'].str.contains('/')] 报错: ValueError Traceback (most recent c ...
- easyui中在formatter: function (value, row,index) {中添加删除方法
{ field : 'abj', title : '操作', align : 'center', resizable:false, width:'10%', formatter: function ( ...
- [转]jQuery: get table column/row index remove table column (by column number)
本文转自:http://www.xinotes.org/notes/note/1087/ <!DOCTYPE html><html><head> <title ...
- SQL Server Reporting Services (SSRS): Reporting Services in SQL Server 2012 (codename "Denali") will support XLSX, DOCX formats. Bye bye 65536 rows limit in XLS files ;)
当SSRS报表的时候,若相应EXCEL是2003以下,在行数超过65536的时候报表会报错 "Microsoft.ReportingServices.ReportProcessing.Han ...
- python 读写 Excel文件
最近用python处理一个小项目,其中涉及到对excel的读写操作,通过查资料及实践做了一下总结,以便以后用. python读写excel文件要用到两个库:xlrd和xlwt,首先下载安装这两个库. ...
随机推荐
- 【线性代数】6-7:SVD分解(Singular Value Decomposition-SVD)
title: [线性代数]6-7:SVD分解(Singular Value Decomposition-SVD) categories: Mathematic Linear Algebra keywo ...
- 自制 yum 源仓库
转自:https://www.cnblogs.com/marility/p/7278374.html 背景 客户服务器为内网机器,centos7系统,且无法与外网连接.需要部署对应的LANMP环境及其 ...
- java集合类-集合框架体系
集合框架体系 集合框架体系是由Collection.Map和 Iterator(迭代器) 实线边框的是实现类,折线边框的是抽象类,而点线边框的是接口 Collection体系 Set接口:元素无序且不 ...
- try catch块的秘密
最近有同事遇到问题: 她在4处手动抛运行异常,5处存在return语句,结果程序在2出现异常时没有抛出运行异常,导致事务不一致. 我们都知道,当程序出现异常时候并且在不采取任何措施的情况下,是会抛出异 ...
- redis详解之cluster模式部署
一.环境说明 1.Operation OS:CentOS7.22.ruby version >= 2.2.23.openssl zlib gcc>=4.8.5 二.开始部署 1.安装rub ...
- 常见的RuntimeException
一般面试中java Exception(runtimeException )是必会被问到的问题常见的异常列出四五种,是基本要求.更多的....需要注意积累了 常见的几种如下: NullPointerE ...
- pycham更换主题
在pycham的file-->Setting-->Editor-->Colors&Fonts
- springmvc返回json对象
1.引入jackson的依赖 <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -- ...
- javaEE项目部署方式
1.手动部署 2.自动化部署 “自动化”的具体体现:向版本库提交新的代码后,应运服务器上自动部署
- 【Python】使用Python处理RAW格式图片,并根据实际情况完成分组打包发送
背景 出游之后,朋友交换的照片格式大多是RAW格式,一些人想要JPG格式,但是百度云盘非会员的下载速度惨不忍睹,所以我想着通过微信群直接传(这个在事后也被证实不能完全解决问题,微信限制了每天传递文件的 ...