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

yipeiwu_com5年前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绘制漏斗图步骤详解

pyecharts中的Funnel函数可以绘制漏斗图,自动根据数据大小生成由大到小自上而下排列的一个漏斗样的图形。 1、导入Funnel模块。 from pyecharts import...

numpy实现合并多维矩阵、list的扩展方法

一、合并多个numpy矩阵 1、首先创建两个多维矩阵 矩阵a的大小为(2,3,2) 矩阵b的大小为(3,2,3) 采用concatentate这个函数就可以合并两个多维矩阵 合并之后...

Python从使用线程到使用async/await的深入讲解

前言 为了简化并更好地标识异步IO,从Python 3.5开始引入了新的语法async和await,可以让coroutine的代码更简洁易读。 请注意,async和await是针对cor...

Python中调用其他程序的方式详解

Python中调用其他程序的方式详解

前言 在Python中,可以方便地使用os模块来运行其他脚本或者程序,这样就可以在脚本中直接使用其他脚本或程序提供的功能,而不必再次编写实现该功能的代码。为了更好地控制运行的进程, 可...

Python的Lambda函数用法详解

在Python中有两种函数,一种是def定义的函数,另一种是lambda函数,也就是大家常说的匿名函数。今天我就和大家聊聊lambda函数,在Python编程中,大家习惯将其称为表达式。...