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. Redis之数据备份与恢复

    Redis 数据备份与恢复 Redis SAVE 命令用于创建当前数据库的备份. 语法 redis Save 命令基本语法如下: redis 127.0.0.1:6379> SAVE 实例 re ...

  2. Java知识弥补-Android开发

    目录 数据结构 1. Map-HashMap 2. StringBuilder 3. List-ArrayList 4. Vector 5. Stack 6. Set 由于这学期开了android课程 ...

  3. [POJ2625][UVA10288]Coupons

    Description Coupons in cereal boxes are numbered 1 to n, and a set of one of each is required for a ...

  4. 【Python】单元测试框架unitest及其高级应用

    Unittest Unittest是python的一个单元测试框架,但是它不仅适用于单元测试,还适用自动化测试用例的开发与执行.我们可以很方便的使用它组织执行测试用例,使用它提供的丰富的断言方法进行测 ...

  5. 类的成员变量修饰 const 和static

    类型 初始化方式 类内(声明) 类外(类实现文件) 构造函数中 构造函数的初始化列表 非静态非常量数据成员 N N Y Y 非静态常量数据成员 N N N Y (must) 静态非常量数据成员 N Y ...

  6. org.springframework.transaction 包改成 spring-tx

    org.springframework.transaction 包改成 spring-tx org.springframework.transaction  3.2.2以后的版本,全改到 spring ...

  7. 使用Zend studio+WAMP来调试Wordpress后台的PHP程序的一些非常关键的信息(原创)

    一.Zend studio代码格式化快捷键:选中代码,Ctrl+Shift+F( 注意,在英文输入发状态下使用!) .Zend studio实用快捷键 :http://www.zendstudio.n ...

  8. sql语句中处理金额,把分换算成元

    问题,sql语句中直接将金额/100返回的结果会有多个小数位. as value from account as acc left join conCategory as cate on acc.ca ...

  9. 移动前端兼容性笔记 - 安卓2.x 自带原生浏览器箭头问题

    这样的箭头用CSS-3实现,整段代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta c ...

  10. block 回调个人理解

    在网上见过这么个面试题 使用block和GCD时要注意些什么?他们是一回事吗?block在ARC和MRC的用法有什么不同?使用时要注意些什么? 首先block 和 GCD 在我看来他们是完全不同的概念 ...