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(写一行空一行解决办法)的更多相关文章

  1. excel批量转换为CSV格式,xls批量导出csv格式

    工具/原料   excel 2013 地址链接:http://pan.baidu.com/s/1c1ZABlu 密码:d3rc 方法/步骤     首选我们把需要导出为CVS的Excel文件整理集中到 ...

  2. 【matlab】将matlab中数据输出保存为txt或dat格式

    将matlab中数据输出保存为txt或dat格式 总结网上各大论坛,主要有三种方法. 第一种方法:save(最简单基本的) 具体的命令是:用save *.txt -ascii x x为变量 *.txt ...

  3. 标注工具doccano导出数据为空的解决办法

    地址:https://github.com/taishan1994/doccano_export doccano_export 使用doccano标注工具同时导出实体和关系数据为空的解决办法.docc ...

  4. python 导出数据到excel 中,一个好用的导出数据到excel模块,XlsxWriter

    最近公司有项目需要导出数据到excel,首先想到了,tablib,xlwt,xlrd,xlwings,win32com[还可以操作word],openpyxl,等模块但是 实际操作中tablib 写入 ...

  5. Python导出数据到Excel表格-NotImplementedError: formatting_info=True not yet implemented

    在使用Python写入数据到Excel表格中时出现报错信息记录:“NotImplementedError: formatting_info=True not yet implemented” 报错分析 ...

  6. 导出数据库数据制成Excel和txt

    引用ICSharpCode.SharpZipLib.dll 1.编写压缩和解压代码 using System; using System.Collections.Generic; using Syst ...

  7. KETTLE单表同步,写入EXCEL和TXT

    以下操作都在5.0.1版本下进行开发,其余版本可以进行自动比对 在平时工作当中,会遇到这种情况,而且很常见.比如:1.自动生成文件TXT或者EXCEL(电信行业该需求居多),上传至某服务器:2.双方数 ...

  8. 文件操作ofstream,open,close,ifstream,fin,依照行来读取数据, fstream,iosin iosout,fio.seekg(),文件写入和文件读写,文件拷贝和文件

     1.ofstream,open,close 写入文件 #include<iostream> #include<fstream> using namespace std; ...

  9. php导出数据到excel,防止身份证等数字字符格式变成科学计数的方法

    而关于php的也有,但是大多都是用phpExcel导出的方法或者spreadsheet等类或者控件之类的导出方法,而我所在维护的系统却用很简单的方法,如下,网上很少有讲如何设置要导出数据的EXcel格 ...

随机推荐

  1. tp5.1报错 页面错误!请稍后再试

    修改框架中convention.php // 应用调试模式 'app_debug' => true, 修改app.php不一定有效.

  2. XML_CPP_ZC_libXml2

    1.错误信息: /* * Use the following function to reset the two global variables * xmlGenericError and xmlG ...

  3. oracle RAC的客户端HA配置

    在ORACLE 9i RAC 环境下,为了做到高可用性,需要对客户端的tnsnames.ora这个文件进行配置,在oracle中这样的配置叫做TAF,这个配置不能使用NETCA配置程序生成.其中ORA ...

  4. JavaScript返回上一页和返回上一级页面并刷新

    JavaScript返回上一页和刷新当前页 window.history.go(-1); //返回上一页 window.history.back(); //返回上一页 //如果要强行刷新的话就是:wi ...

  5. vue/webpack的一些小技巧

    都知道我比较懒,今天给大家分享的就是如何让自己省事. 一.vue修改打包后的结构(不知道怎么描述合理,看效果图) /config/index.js 默认的: 修改的:(顺手修改了打包后的文件名) 这样 ...

  6. ASP.NET Page 指令

    一些重要的Page指令 虽然Page公开了很多属性,让我们可以在运行时调整它的状态与行为,但是,还有些重要的参数却是以“指令”方式提供的,需要在设计时就指定.下面是我整理的一些我认为 比较重要并且经常 ...

  7. sgu 146. The Runner 取模技巧 难度:1

    146. The Runner time limit per test: 0.25 sec.memory limit per test: 4096 KB input: standard inputou ...

  8. 分析hello.java文件

    使用JavaServer Faces技术的Web模块示例 1.hello1: hello1应用程序是一个web模块,它使用JavaServer Faces技术来显示问候和响应.可以使用文本编辑器查看应 ...

  9. DbVisualizer 连接 SQL Server 2008配置

    软件准备 1.SQLServer驱动准备,可在该连接下载:https://pan.baidu.com/s/1i4V1Ivz (1). 解压JDBC for SQLServer drive.rar,得到 ...

  10. Mysql基本操作(远程登陆,启动,停止,重启,授权)

    1.查看mysql版本 方法一:status; 方法二:select version(); 2.Mysql启动.停止.重启常用命令 a.启动方式 1.使用 service 启动: [root@loca ...