daily pastebin goal
24%
SHARE
TWEET

Untitled

a guest Apr 21st, 2017 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '''
  2. This script generates square shaped transitions
  3. for a list of given data points.
  4.  
  5. ### Example
  6. Input:
  7. x,y
  8. 0,100
  9. 5,430
  10. 10,200
  11.  
  12. Output:
  13. x,y
  14. 0,100
  15. 5,100
  16. 5,430
  17. 10,430
  18. 10,200
  19.  
  20. '''
  21.  
  22. import csv
  23. import sys
  24.  
  25. if(len(sys.argv) < 3):
  26.     print("Usage: " + sys.argv[0] + " <input csv file> <output csv file>")
  27.     sys.exit(1)
  28.  
  29. infile = open(sys.argv[1],"r")
  30. reader = csv.reader(infile,delimiter="\t")
  31.  
  32. outfile = open(sys.argv[2],"w")
  33. writer = csv.writer(outfile)
  34.  
  35.  
  36. last = None
  37. skipHeader = True
  38. for row in reader:
  39.     if(skipHeader):
  40.         writer.writerow(row)
  41.         skipHeader = False
  42.         continue
  43.     if(last != None):
  44.         writer.writerow([row[0], last])
  45.  
  46.     last = row[1]
  47.     writer.writerow(row)
  48.  
  49. infile.close()
  50. outfile.close()
RAW Paste Data
Top