python txt转csv从文本文件转换为CSV格式的数据集

Python可以使用csv模块将txt文件转换为csv文件。是一个示例代码:import csv

Python可以使用csv模块将txt文件转换为csv文件。是一个示例代码:

import csv

# Open the input file in read mode and output file in write mode

with open('input.txt', 'r') as read_obj, \

open('output.csv', 'w', newline='') as write_obj:

# Create a csv.reader object from the input file object

csv_reader = csv.reader(read_obj)

# Create a csv.writer object from the output file object

csv_writer = csv.writer(write_obj)

# Read each row of the input csv file as list

for row in csv_reader:

# Write the list to the output file

csv_writer.writerow(row)

本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处

(825)
python编程入门经典pdf从入门到精通
上一篇
python实现kmeans算法:使用Python实现K-Means聚类算法的技术实现
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(4条)