python读写csv

首先导入库:import csv

  1. 读文件
with open(filename) as fp:
    f_tsv = csv.reader(fp, delimiter=',')
    for line in f_tsv:
        print(line)
  1. 写文件
with open(filename, 'w') as fw:
        writer = csv.writer(fw)
        writer.writerow(['X', 'Y', 'Z', filename, 'period:' + str(number)])  #一行
        writer.writerows(data[start:end, :])    #多行

你可能感兴趣的:(python读写csv)