with open('test.csv', 'r') as r_file:
# 读取csv文件内的所有内容
file_read = csv.reader(r_file)
for row in islice(file_read, 0, None): # 如果第一行是列名,用islice函数直接跳过第一行 islice(文件名,跳过的行数,None)
# 处理第六列数据
print(row)
print('-'*20)
row[2] += 'copy' # 第六列数据
row[3] += 'copy' # 第六列数据
with open('names.csv', 'a', newline='') as w_file: # 若没有newline=''每读入一行数据后跟一个空行
writer = csv.writer(w_file)
writer.writerow(row)```
refer [参考链接](https://www.cnblogs.com/jiaxinwei/p/11696002.html)
编辑csv文件
最新推荐文章于 2024-03-20 06:58:59 发布