python 保存数据为excel格式和txt格式

这篇博客介绍了如何使用Python将数据保存为Excel和TXT格式。对于Excel,它提到使用write函数并指出Excel文件最多存储65536行数据的限制。对于TXT保存,方法更为简洁,直接提供相关代码实现。
摘要由CSDN通过智能技术生成

 excel 保存方法:

book = xlwt.Workbook() 
#创建表单
sheet = book.add_sheet(u'sheet1',cell_overwrite_ok=True)

sheet.write(0,0,'id')
sheet.write(0,1,'text')
sheet.write(0,2,'user_id')
sheet.write(0,3,'geo_coordinates1')
sheet.write(0,4,'geo_coordinates2')
sheet.write(0,5,'created_at')
i =1
for all in searchRes:
    sheet.write(i,0,all['_id'])
    sheet.write(i,1,all['text'])
    sheet.write(i,2,all['user_id'])
    sheet.write(i,3,all['geo']['coordinates'][0])
    sheet.write(i,4,all['geo']['coordinates'][1])
    sheet.write(i,5,all['created_at'])
    i=i+1
    if(i==65530):
        break
book.save('Excel_Workbook.xls')

workshop 的写入方法十分简洁:使用write函数

            write(i,j,data)    ##i,j分别为excel的i行j列的位置。起始为0,0

            最后记

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值