0

I have a csv file that contains time (hh:mm:ss) and date (mm/dd/yyyy) fields, and sixteen more fields.

Generally the time field display time every 30'', but sometime the separation might be more (minutes or even hours).

For instance:

1/27/2011 12:10:00 
1/27/2011 12:10:30 
1/27/2011 12:11:00 
1/27/2011 12:15:00

I need to add new lines (as many as the gap between them) every time the gap between a line and the next is more the 30'', and fill them out with the values from the first line in the gap.

I would like to do it without working in a database environment. Is it possible? If so, can you give me some good tips?

1
  • 1
    Could you give an input example, please ? Your explanation of the structure of the file to be treated is unclear. Commented Mar 16, 2011 at 18:38

3 Answers 3

1

Buffer the last two lines, calculate the time difference between them, and write output based upon the results of a conditional test on that time difference.

Sign up to request clarification or add additional context in comments.

Comments

0

Have you checked the manual? http://docs.python.org/library/csv.html there are also examples at the end

The first idea that comes to my mind is iterating over the rows in the csv and copying them to a new blank csv one row at a time, if current row and row before are more than 30" apart, then add row before the necessary amount of times to the new csv.

Comments

0

I'm not sure I understand your situation. If this is how the file is set up:

1/27/2011 12:10:00 xxx xxx xxx xx...
1/27/2011 12:10:30 xxx xxx xxx xx...
1/27/2011 12:10:00 xxx xxx xxx xx...
1/27/2011 12:15:00 xxx xxx xxx xx...

then you can read the file (or maybe just the last two lines) into your program, maybe as a list of lines, check to see if the time difference between the two lines is > 30", and if need be insert two lines into the array and rewrite the whole file. Or, instead of that, you could try to edit the file in place.

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.