Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. for name in filenames:
  2. with open(name, 'r') as f:
  3. reader = csv.reader(f)
  4. with open('updated_' + name, 'w') as f:
  5. writer = csv.writer(f)
  6. for row in reader:
  7. first3 = row[:3] #take first 3 elements of the input list
  8. rest = row[3:] #take the rest of the elements in input list excluding original 3
  9. current5 = rest[:5] #take only the next 5 elements in the list before date changes
  10. while len(rest) > 0: #loop through the entire input row with current 5 changing until it runs out
  11. writer.writerows(first3 + current5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement