import csv
from shutil import move
from tempfile import NamedTemporaryFile
with open("infile", 'rb') as csvfile, NamedTemporaryFile(dir=".",delete=False) as temp:
w = csv.writer(temp)
r = csv.reader(csvfile)
for row in r:
dt = row[5].split("/")
row[5] = "{}/{}/{}".format(row[-1],row[1],row[0])
w.writerow(row)
move(temp.name,"infile")
如果可以将文件读入R,则可以使用
如果有必要,再写回文件。在
不要转换为日期时间,只需拆分om
/
并使用str.format
来交换年份和日期:将更新的行写入
NamedTemporaryFile
并使用舒蒂尔。快走用修改后的内容替换原始文件。在相关问题 更多 >
编程相关推荐