Skip to content

Instantly share code, notes, and snippets.

@vsee
Created April 21, 2017 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vsee/9e989ee6d314aea0672a084086568465 to your computer and use it in GitHub Desktop.
Save vsee/9e989ee6d314aea0672a084086568465 to your computer and use it in GitHub Desktop.
generates square shaped transitions for a list of given data points.
'''
This script generates square shaped transitions
for a list of given data points.
### Example
Input:
x,y
0,100
5,430
10,200
Output:
x,y
0,100
5,100
5,430
10,430
10,200
'''
import csv
import sys
if(len(sys.argv) < 3):
print("Usage: " + sys.argv[0] + " <input csv file> <output csv file>")
sys.exit(1)
infile = open(sys.argv[1],"r")
reader = csv.reader(infile,delimiter="\t")
outfile = open(sys.argv[2],"w")
writer = csv.writer(outfile)
last = None
skipHeader = True
for row in reader:
if(skipHeader):
writer.writerow(row)
skipHeader = False
continue
if(last != None):
writer.writerow([row[0], last])
last = row[1]
writer.writerow(row)
infile.close()
outfile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment