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

作者:bymaymay 时间:2022-02-28 05:07:01 

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')

结果

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

将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的实例

来源:https://blog.csdn.net/bymaymay/article/details/81299300

标签:python,字符串,list,excel,txt
0
投稿

猜你喜欢

  • Python实现将mp3音频格式转换为wav格式

    2023-09-18 15:50:02
  • 教你用Python matplotlib库制作简单的动画

    2021-08-20 02:58:49
  • 用err.raise自定义错误信息

    2008-02-20 12:48:00
  • Python制作CSDN免积分下载器

    2021-12-25 03:46:35
  • python自动发送邮件脚本

    2023-01-24 07:56:28
  • Python帮你解决手机qq微信内存占用太多问题

    2023-04-02 18:14:44
  • 利用xmlhttp和adodb.stream加缓存技术下载远程Web文

    2009-04-23 18:33:00
  • 简单且有用的Python数据分析和机器学习代码

    2021-03-27 13:13:27
  • python中绑定方法与非绑定方法的实现示例

    2021-01-03 03:59:13
  • Python入门教程 超详细1小时学会Python

    2023-06-13 23:34:12
  • 利用Python在一个文件的头部插入数据的实例

    2023-02-06 13:04:33
  • SQL Server技巧之快速得到表的记录总数

    2011-01-04 14:36:00
  • 拿来就用!Python批量合并PDF的示例代码

    2021-01-02 15:39:23
  • Python集合之set和frozenset的使用详解

    2021-06-26 22:41:20
  • PHP PDOStatement::errorCode讲解

    2023-06-11 12:40:23
  • ORACLE常见错误代码的分析与解决(二)

    2010-08-02 13:31:00
  • eWebEditor不支持IE8/IE7的解决方法

    2010-02-28 10:27:00
  • python使用py2neo创建neo4j的节点和关系

    2021-09-25 01:03:28
  • 可以在线创建文件夹吗?

    2009-11-01 18:07:00
  • pytest使用parametrize将参数化变量传递到fixture

    2022-03-28 23:30:18
  • asp之家 网络编程 m.aspxhome.com