您好我有一个python脚本,它将.csv文件中的时间戳列从点表示法更改为“日期时间TSQL”表示法:
在执行代码之前,这一行是这样的:
send,2007.10.04.10.11.11.669,Server,Data,Client,TYPE=STP,Length=329,Cnt=11
执行代码后,它看起来像这样:
send,2007-10-04 10:11:11.669,Server,Data,Client,TYPE=STP,Length=329,Cnt=11
我想在第一次列之后以新格式追加相同的时间,它看起来像这样:
send,2007-10-04 10:11:11.669,2007-10-04 10:11:11.669,Server,Data,Client,TYPE=STP,Length=329,Cnt=11
这是脚本:
import csv
cr = csv.reader(open("ActualTrace_01 - short2Times.csv", "rb"))
output = csv.writer(open("GermanygoalInputFormatActualTrace_01 - short.csv", "wb"))
for row in cr:
dateTimeContentsSend = row[1].split(".")
finishSend = dateTimeContentsSend[0] + "-" + dateTimeContentsSend[1] + "-" + dateTimeContentsSend[2] + " " + dateTimeContentsSend[3] + ":"
finishSend+= dateTimeContentsSend[4] + ":" + dateTimeContentsSend[5] + "." + dateTimeContentsSend[6]
row[1] = finishSend
output.writerow(row)
这里的所有主题都没用,如果你只是说row [1] = finishSend +“,”+ finishSend 它在行[1]中使用这样的引号
send,"2007-10-04 10:11:11.669,2007-10-04 10:11:11.684",Server,Data,Client,TYPE=STP,Length=329,Cnt=11
答案 0 :(得分:1)
您是否(仅在row[1] = finishSend
之后)?
row.insert(2, row[1])