【问题标题】:How to covert each row of a csv file to a separate text file?如何将 csv 文件的每一行转换为单独的文本文件?
【发布时间】:2021-07-05 10:07:24
【问题描述】:

【问题讨论】:

  • 看看这个link
  • 要获得答案,请提供有关您尝试过的内容、使用的语言等信息。为了提高可读性,请仅将一两个词链接到电子表格图像。

标签: python pandas yolo


【解决方案1】:

也许我可以试试这个:

import csv
import os 

base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
csv_file open(base + "/any.csv", mode='r')
dialect = csv.excel()
dialect.delimiter = ';'
csv_reader = csv.DictReader(csv_file, dialect=dialect)
txt_file open(base + "/any.csv", mode='w') 
txt_file = txt.writer()

for row in csv_reader:
   txt_file.writerow((row, ))

txt_file.save()
txt_file.close()
csv_file.close()

希望对你有帮助,问候。

【讨论】:

    猜你喜欢
    • 2021-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多