Python将数据写入excel或者txt,读入csv格式或xls文件,写入csv(写一行空一行解决办法)
1.写入excel,一开始不需要自己新建一个excel,会自动生成
attribute_proba是我写入的对象

import xlwt
myexcel = xlwt.Workbook()
sheet = myexcel.add_sheet('sheet')
si=-1
sj=-1
for i in attribute_proba:
si=si+1
for j in i:
sj=sj+1
sheet.write(si,sj,str(j))
sj=-1
myexcel.save("attribute_proba_big.xls")
2.写入csv,注意要打上 newline="",否则会写一行空一行

import csv
with open("tech_problem.csv","w",newline="") as csvfile:
writer = csv.writer(csvfile)
for i in range(52):
writer.writerow([i,bol[i]])
slast的结构是有列表组成的列表
ls=[]
ls.append(number)
slast.append(ls)
可以直接写
import csv
with open("final.csv","w",newline="") as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T'])
writer.writerows(slast)
3.写入txt,一开始就需要你新建一个txt文件

f=open('F:/goverment/myfinalcode/predict.txt', 'w')
for i in range(s):
f.write(str(predict[i]))
f.write('\n')
f.write("写好了")
f.close()
4.读入csv

file = 'F:/goverment/myfinalcode/test_big.csv'
fo=open(file)
ls=[]
for line in fo:
line=line.replace("\t",",")
line=line.replace("\n",",")
line=line.replace("\"",",")
ls.append(line.split(","))
for i in ls:
li=[]
for j in i:
if j == '':
continue
li.append(str(j))
testdata.append(li)

from pandas import read_csv
data_set = read_csv("F:/goverment/excel operating/type_in.csv")
data = data_set.values[:, :]
test_data = []
for line in data:
ls = []
for j in line:
ls.append(j)
test_data.append(ls)
5.读入xls

import xlrd
file = 'F:/goverment/myfinalcode/test_big_label.xls'
wb = xlrd.open_workbook(file)
ws = wb.sheet_by_name("Sheet1")
for r in range(ws.nrows):
col = []
for c in range(ws.ncols):
col.append(ws.cell(r, c).value)
testlabel.append(col)
Python将数据写入excel或者txt,读入csv格式或xls文件,写入csv(写一行空一行解决办法)的更多相关文章
- excel批量转换为CSV格式,xls批量导出csv格式
工具/原料 excel 2013 地址链接:http://pan.baidu.com/s/1c1ZABlu 密码:d3rc 方法/步骤 首选我们把需要导出为CVS的Excel文件整理集中到 ...
- 【matlab】将matlab中数据输出保存为txt或dat格式
将matlab中数据输出保存为txt或dat格式 总结网上各大论坛,主要有三种方法. 第一种方法:save(最简单基本的) 具体的命令是:用save *.txt -ascii x x为变量 *.txt ...
- 标注工具doccano导出数据为空的解决办法
地址:https://github.com/taishan1994/doccano_export doccano_export 使用doccano标注工具同时导出实体和关系数据为空的解决办法.docc ...
- python 导出数据到excel 中,一个好用的导出数据到excel模块,XlsxWriter
最近公司有项目需要导出数据到excel,首先想到了,tablib,xlwt,xlrd,xlwings,win32com[还可以操作word],openpyxl,等模块但是 实际操作中tablib 写入 ...
- Python导出数据到Excel表格-NotImplementedError: formatting_info=True not yet implemented
在使用Python写入数据到Excel表格中时出现报错信息记录:“NotImplementedError: formatting_info=True not yet implemented” 报错分析 ...
- 导出数据库数据制成Excel和txt
引用ICSharpCode.SharpZipLib.dll 1.编写压缩和解压代码 using System; using System.Collections.Generic; using Syst ...
- KETTLE单表同步,写入EXCEL和TXT
以下操作都在5.0.1版本下进行开发,其余版本可以进行自动比对 在平时工作当中,会遇到这种情况,而且很常见.比如:1.自动生成文件TXT或者EXCEL(电信行业该需求居多),上传至某服务器:2.双方数 ...
- 文件操作ofstream,open,close,ifstream,fin,依照行来读取数据, fstream,iosin iosout,fio.seekg(),文件写入和文件读写,文件拷贝和文件
1.ofstream,open,close 写入文件 #include<iostream> #include<fstream> using namespace std; ...
- php导出数据到excel,防止身份证等数字字符格式变成科学计数的方法
而关于php的也有,但是大多都是用phpExcel导出的方法或者spreadsheet等类或者控件之类的导出方法,而我所在维护的系统却用很简单的方法,如下,网上很少有讲如何设置要导出数据的EXcel格 ...
随机推荐
- IE8 JSON is not defined
问题原因: 昨天遇到了一个问题.就是用ajax从后台查询数据时,返回信息无法显示,经过提示发现是IE控制台提示: JSON is not defined 错误. 而且这个问题在本人自己的电脑上是不存在 ...
- FastJson/spring boot: json输出方法二
1.引入FastJson依赖包 <!-- FastJson --> <dependency> <groupId>com.alibaba</groupId> ...
- CSS cursor 和 opacity 属性
cursor :一些不同的光标,当设置该属性之后,鼠标指上去会随着属性而改变. 举例: <span style="cursor:crosshair">十字线</s ...
- Android之扫描二维码和根据输入信息生成名片二维码
开发中常常遇到二维码扫码操作,前段时间做项目要实现该功能,于是网上查找资料实现了,现在把他做出来给各位分享一下,主要包含了二维码扫描和生成二维码名片. 先来看看效果图: 生成的二维码,打开微信扫一 ...
- Android之水波纹点击效果(RippleView)
Android5.0后各种炫的效果纷纷出来,写这篇博客主要是讲的是按钮点击效果带有的水波纹(波浪式). 当然我写的这个是自定义来实现的,在低版本(5.0一下)也可以实现点击效果.看看效果图: 上图可看 ...
- 识别User Agent屏蔽一些Web爬虫防采集
识别User Agent屏蔽一些Web爬虫防采集 from:https://jamesqi.com/%E5%8D%9A%E5%AE%A2/%E8%AF%86%E5%88%ABUser_Agent%E5 ...
- java并发编程:线程安全管理类--原子包--java.util.concurrent.atomic
java.util.concurrent.atomic 的描述 AtomicBoolean 可以用原子方式更新的 boolean 值. AtomicInteger 可以用原子方式更新的 int 值. ...
- 解决Myeclipse闪退问题
才安装好Myeclipse就出了问题,打开之后没过多久就自动退出了,看了好多解决方法都无效,后来才找到正确路径,转载过来方便跟我遇到同样问题的小伙伴,尽快解决 转载自:http://blog.csdn ...
- jquery分页滑动插件(鼠标可控制上下滑动)
这个插件非常好用 http://www.swiper.com.cn/
- STL标准库-容器-list
技术在于交流.沟通,本文为博主原创文章转载请注明出处并保持作品的完整性. list 表示非连续的内存区域,并通过一对指向首尾元素的指针双向链接起来,从而允许向前和向后两个方向进行遍历.在list 的任 ...