python读取文件存到excel中
用xlwt模块执行代码报下面的错
ValueError: column index (256) not an int in range(256)
xlwt 模块看源码说最大列只支持255列,所以超过这个值就报错了,改用xlsxwriter模块
import xlsxwriter
workbook = xlsxwriter.Workbook('chineseQA.xlsx') #创建工作簿
worksheet = workbook.add_worksheet() #创建工作表 title=['question','answer']
lie = 0#定义要插入的列,0是第一列
for i in title:
worksheet.write(0,lie,i)
lie+=1 hang = 1#定义要插入的行,1是第二行
with open('question',encoding='utf-8') as f:
lie1 = 0#定义要插入的列
for i in f.readlines():
lis=i.strip()
worksheet.write(hang, lie1, lis)
hang+=1#行数加一
lie1+=1#列数加一 hang=1
with open('answer',encoding='utf-8') as f:
lie1 = 1
for i in f.readlines():
lis=i.strip()
worksheet.write(hang, lie1, lis)
hang+=1
lie1+=1
workbook.close()
参考下面这篇博客
http://www.mamicode.com/info-detail-2252921.html
python读取文件存到excel中的更多相关文章
- Python 读取文件中unicode编码转成中文显示问题
Python读取文件中的字符串已经是unicode编码,如:\u53eb\u6211,需要转换成中文时有两种方式 1.使用eval: eval("u"+"\'" ...
- python操作txt文件中数据教程[3]-python读取文件夹中所有txt文件并将数据转为csv文件
python操作txt文件中数据教程[3]-python读取文件夹中所有txt文件并将数据转为csv文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 python操作txt文件中 ...
- python 读取文件时报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 205: illegal multib
python 读取文件时报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 205: illegal multib ...
- python读取文件首行和最后一行
python读取文件最后一行两种方式 1)常规方法:从前往后依次读取 步骤:open打开文件. 读取文件,把文件所有行读入内存. 遍历所有行,提取指定行的数据. 优点:简单,方便 缺点:当文件大了以后 ...
- 【python】python读取文件报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 2: illegal multibyte sequence
python读取文件报错UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 2: illegal multibyte ...
- python 读取文件时报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 205: illegal multibyte sequence
python读取文件时提示"UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 205: illegal m ...
- Xilinx FPGA引脚txt文件导入excel中
需求 为了把xilinx FPGA的官方引脚文件txt转成excel文件(实际官网中有对应的csv文件就是excel文件了...) xilinx FPGA引脚地址:https://china.xili ...
- 解决 python 读取文件乱码问题(UnicodeDecodeError)
解决 python 读取文件乱码问题(UnicodeDecodeError) 确定你的文件的编码,下面的代码将以'utf-8'为例,否则会忽略编码错误导致输出乱码 解决方案一 with open(r' ...
- python 读取文件read.csv报错 OSError: Initializing from file failed
小编在用python 读取文件read.csv的时候 报了一个错误 OSError: Initializing from file failed 初始化 文件失败 检查了文件路径,没问题 那应该是我文 ...
随机推荐
- Cent OS安装My Sql
因为公司的需要,所以就自己学习了一下在Linux上安装MySQL,但是翻查了好多博客,没有特别清楚,自己写下来好好总结一下 一.系统环境 CentOS-6.3-i386-bin-DVD1 二.下载My ...
- apktool反编译时各种问题汇总
问题1:apktool d -d 时出现错误Error occured while disassembling class办法:这不是你的错误,这是apktool本身的错误,目前正式release的1 ...
- mysql 随机取数据
SELECT * FROM table WHERE id >= (SELECT FLOOR(RAND()*MAX(id)) FROM table ) ORDER BY idLIMIT 1; 这样 ...
- C# string[ ][ ] 与string[,]
1.string[][] 是一维数组,数组中的元素是string[],相当于锯齿数组 例如:string[][] arrar = new string[][] { n ...
- mfs客户端挂载
1.安装fuse yum install fuse fuse-devel 2.加载fuse模块 modprobe fuse 3.创建mfs用户 useradd mfs -s /sbin/nologin ...
- Mac下配置mnmp环境
虽然比较喜欢玩下新语言, 但是php还是常会用到的. lnmp很多人都听过, 但是不能用在Mac上面, 另外还有个mnpp但在osx 10.8.3下面跑不起来.所以自己手动一步步安装, 整理了方便安装 ...
- Flask--上下文源码流程
- MHA安装配置
1. 前言 MHA可以在较短的时间内实现自己主动故障检測和故障转移,通常在10-30秒以内;在复制框架中,MHA可以非常好地解决复制过程中的数据一致性问题,因为不须要在现有的replication中加 ...
- Swift_1_基本数据类型
import Foundation println("Hello, World!"); var v1 = 1; var v2 = 2; println(" v1 is \ ...
- Failed to read artifact descriptor for org.apache.httpcomponents:httpmime:jar
额,在Stackoverflow上找到了一个答案: I had this in eclipse and did this which fixed it(even though my command l ...