1

Hello I have a python script which changes a timestamp column in a .csv file from dot notation to "date time TSQL" notation:

One row looks like this before executing the code:

send,2007.10.04.10.11.11.669,Server,Data,Client,TYPE=STP,Length=329,Cnt=11

after executing the code it looks like this:

send,2007-10-04 10:11:11.669,Server,Data,Client,TYPE=STP,Length=329,Cnt=11

I want to append the same time in the new format after the first time column, that it looks like this:

send,2007-10-04 10:11:11.669,2007-10-04 10:11:11.669,Server,Data,Client,TYPE=STP,Length=329,Cnt=11

Here is the Script:

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)

All Threads here were not useful and if you just say row[1] = finishSend + "," + finishSend it makes it in row[1] with quotes like this

send,"2007-10-04 10:11:11.669,2007-10-04 10:11:11.684",Server,Data,Client,TYPE=STP,Length=329,Cnt=11

1 Answer 1

1

Are you after (just after row[1] = finishSend)?

row.insert(2, row[1]) 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.