python将字符串list写入excel和txt的实例

yipeiwu_com6年前Python基础

docs = [‘icassp improved human face identification using frequency domain representation facial asymmetry', ‘pattern recognition unsupervised methods classification hyperspectral images low spatial resolution', ‘iscas post layout watermarking method ip protection', ‘computers mathematics applications tauberian theorems product method borel cesàro summability', ‘ieee t. geoscience remote sensing mirs all-weather 1dvar satellite data assimilation retrieval system']

将docs写入excel

docs = [doc.encode('latin-1', 'ignore') for doc in docs]
# convert list to array
docs_array = np.array(docs)
print(type(docs_array))
# saving...
np.savetxt('/Users/Desktop/portrait/jour_paper_docs.csv', docs_array, fmt='%s', delimiter=',')
print('Finish saving csv file')

结果

将docs写入txt

def save(filename, docs):
 fh = open(filename, 'w', encoding='utf-8')
 for doc in docs:
  fh.write(doc)
  fh.write('\n')
 fh.close()
save('/Users/Desktop/portrait/jour_paper_docs.txt', docs)

结果

以上这篇python将字符串list写入excel和txt的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python单元测试与测试用例简析

本文实例讲述了Python单元测试与测试用例。分享给大家供大家参考,具体如下: 单元测试与测试用例 简介 测试用例是一组单元测试,这些单元测试一起核实函数在各种情形下的行为都符合要求 要...

详解python中sort排序使用

1.前言 昨天一学妹问我一个关于python的问题,当时在外忙碌,没时间细看。今天看一下,咋一看我还真的不知道这个问题,bookinfo.sort(reverse=True ,key=l...

python使用sklearn实现决策树的方法示例

python使用sklearn实现决策树的方法示例

1. 基本环境 安装 anaconda 环境, 由于国内登陆不了他的官网 https://www.continuum.io/downloads, 不过可以使用国内的镜像站点: https...

Tensorflow的可视化工具Tensorboard的初步使用详解

Tensorflow的可视化工具Tensorboard的初步使用详解

当使用Tensorflow训练大量深层的神经网络时,我们希望去跟踪神经网络的整个训练过程中的信息,比如迭代的过程中每一层参数是如何变化与分布的,比如每次循环参数更新后模型在测试集与训练集...

Python3.4学习笔记之类型判断,异常处理,终止程序操作小结

本文实例讲述了Python3.4类型判断,异常处理,终止程序操作。分享给大家供大家参考,具体如下: python3.4学习笔记 类型判断,异常处理,终止程序,实例代码: #idle中...