python將字符串list寫入excel和txt的實例
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')
結(jié)果

將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)
結(jié)果

以上這篇python將字符串list寫入excel和txt的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
TensorFlow命名空間和TensorBoard圖節(jié)點實例
今天小編就為大家分享一篇TensorFlow命名空間和TensorBoard圖節(jié)點實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-01-01
Python監(jiān)聽鍵盤和鼠標(biāo)事件的示例代碼
這篇文章主要介紹了Python監(jiān)聽鍵盤和鼠標(biāo)事件的示例代碼,幫助大家更好的理解和使用python,提高辦公效率,感興趣的朋友可以了解下2020-11-11
python調(diào)用騰訊云實名認(rèn)證接口辨別身份證真假
這篇文章主要為大家介紹了python辨別身份真假之騰訊云身份證實名認(rèn)證接口,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-05-05
基于Python實現(xiàn)圖片瀏覽器的應(yīng)用程序
圖像瀏覽器應(yīng)用程序是一種非常常見和實用的工具,這篇文章就來為大家介紹一下如何使用Python編程語言和wxPython庫創(chuàng)建一個簡單的圖像瀏覽器應(yīng)用程序,感興趣的可以了解下2023-10-10
python命令行參數(shù)解析OptionParser類用法實例
這篇文章主要介紹了python命令行參數(shù)解析OptionParser類用法實例,需要的朋友可以參考下2014-10-10
Django 導(dǎo)出項目依賴庫到 requirements.txt過程解析
這篇文章主要介紹了Django 導(dǎo)出項目依賴庫到 requirements.txt過程解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2019-08-08
Python實現(xiàn)創(chuàng)建詞云的示例詳解
詞云一般是根據(jù)輸入的大量詞語生成的,如果某個詞語出現(xiàn)的次數(shù)越多,那么相應(yīng)的大小就會越大,本文將利用wordcloud模塊實現(xiàn)詞云生成,需要的可以參考下2023-10-10

