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中线程编程之threading模块的使用详解

threading.Thread Thread 是threading模块中最重要的类之一,可以使用它来创建线程。有两种方式来创建线程:一种是通过继承Thread类,重写它的run方法;另...

Python箱型图绘制与特征值获取过程解析

Python箱型图绘制与特征值获取过程解析

这篇文章主要介绍了Python箱型图绘制与特征值获取过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 它主要用于反映原始数据分布...

Python3分析处理声音数据的例子

将音频文件拷贝到程序所在目录即可。 如下所示: #!/usr/bin/env python # encoding: utf-8 """ @Company:华中科技大学电气学院聚变与等...

python实现ip代理池功能示例

本文实例讲述了python实现ip代理池功能。分享给大家供大家参考,具体如下: 爬取的代理源为西刺代理。 用xpath解析页面 用telnet来验证ip是否可用 把有效的i...

python画图系列之个性化显示x轴区段文字的实例

python画图系列之个性化显示x轴区段文字的实例

今天在写一个研究生创新项目申报书时涉及到一个python画图问题,对于在x轴各个区段显示自定义的字符串有些疑问,特此记录。 界面如下所示: 代码如下所示: import matpl...