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设计】。

相关文章

对Python3 解析html的几种操作方式小结

解析html是爬虫后的重要的一个处理数据的环节。一下记录解析html的几种方式。 先介绍基础的辅助函数,主要用于获取html并输入解析后的结束 #把传递解析函数,便于下面的修改 de...

Python函数any()和all()的用法及区别介绍

引子 平常的文本处理工作中,我经常会遇到这么一种情况:用python判断一个string是否包含一个list里的元素。 这时候使用python的内置函数any()会非常的简洁: fr...

Python NumPy库安装使用笔记

1. NumPy安装 使用pip包管理工具进行安装 复制代码 代码如下: $ sudo pip install numpy 使用pip包管理工具安装ipython(交互式shell工具...

Python实现简单层次聚类算法以及可视化

本文实例为大家分享了Python实现简单层次聚类算法,以及可视化,供大家参考,具体内容如下 基本的算法思路就是:把当前组间距离最小的两组合并成一组。 算法的差异在算法如何确定组件的距离,...

基于Python和PyYAML读取yaml配置文件数据

基于Python和PyYAML读取yaml配置文件数据

一、首先我们需要安装 PyYAML 第三方库 直接使用 pip install PyYAML 就可以(这里我之前是装过的,所以提示我PyYAML已经在这个目录下了,是5.1.2版本的)...