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使用psutil获取进程信息的例子

psutil是什么 psutil是一个能够获取系统信息(包括进程、CPU、内存、磁盘、网络等)的Python模块。主要用来做系统监控,性能分析,进程管理,像glances也是基于psut...

Python交互式图形编程的实现

Python交互式图形编程的实现

一、 1、图形显示 图素法 像素法 图素法---矢量图:以图形对象为基本元素组成的图形,如矩形、 圆形 像素法---标量图:以像素点为基本单位形成图形 2、图形用户界...

简单使用Python自动生成文章

  为了应付某些情况,需要做17份记录。虽然不很重要,但是17份完全雷同也不很好。大体看了一下,此记录大致分为四段。于是决定每段提供四种选项,每段四选一,拼凑成四段文字,存成一个文件。文...

django之session与分页(实例讲解)

django之session与分页(实例讲解)

前面我们介绍了cookies,主要应用在用户登录上,保存用户登录状态,不过cookies直接放在了浏览器上,安全性较低,所以我们便引出了session功能与cookies相同,不同的是它...

pytorch索引查找 index_select的例子

index_select anchor_w = self.FloatTensor(self.scaled_anchors).index_select(1, self.LongTensor...