csvファイルの内容を読み、単語に書き込みます

csvを読む単語を書く

コード:

#!/usr?bin/env/ python
# -*- coding:utf-8 -*-
# author: lai zheng laing
# datetime: 2020/10/23 15:53
# software: PyCharm
import docx
import csv
file_path = 'E:/The_data_for_topiclcrlaw/yi_qing_fangkong_data/爬取的疫情防控数据.csv'
with open(file_path,encoding='utf-8') as file_name:   # 打开文件所在的位置
    reader =csv.reader(file_name)
    result = list(reader)            # 存入列表
    del result[0]
    # str_convert = ''.join(result[0][:])
    # print(str_convert)
    a = (len(result[:][:]))
    b = (len(result[0][:]))
    doc = docx.Document()  # 创建一个空的word
    for i in range(a):
        str_convert = ''.join(result[i][:])    # 将列表的内容写入字符串
        str_num = ''.join(str_convert)         # 创建一个总的字符串
        doc.add_paragraph(str_num)             # 写入word
        print(str_num)
    doc.save('C:/Users/acer/Desktop/test.doc')  # 保存word

ここに写真の説明を挿入## 結果:

ここに写真の説明を挿入

おすすめ

転載: blog.csdn.net/qq_42794767/article/details/109256494