當前位置:成語大全網 - 新華字典 - python怎麽讀取修改csv文件,並且重新創建在壹個文件夾中

python怎麽讀取修改csv文件,並且重新創建在壹個文件夾中

參考方法如下:

逐行處理:

for line in open("samples/sample.csv"):

title, year, director = line.split(",") //以“,”號為分割,按逗號將數據分成三部分;

print year, title

使用csv模塊處理:

import csv

reader = csv.reader(open("samples\sample.csv"))

for title, year, director in reader:

print year, title

改變分隔符;