这篇教程python编辑excel--更改的最后一列写得很实用,希望能帮到您。
import os
import csv
path=os.getcwd()
filenames = os.listdir(path)
for filename in filenames:
if filename.endswith('.csv'):
r=csv.reader(open(filename))
new_data = []
for row in r:
row[-1] = row[-1].replace("S-D", "S")
new_data.append(row)
newfilename = "".join(filename.split(".csv")) + "_edited.csv"
with open(newfilename, "w") as f:
writer = csv.writer(f)
writer.writerows(new_data)
python 删除特定行数据_Python实现和Excel基础功能对应关系 Python实现对csv的批量处理并保存 |