Created
October 22, 2015 16:12
-
-
Save f-ewald/cb00779a8d6f30549ca6 to your computer and use it in GitHub Desktop.
Revisions
-
f-ewald created this gist
Oct 22, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,55 @@ # file formatter for csv files import os ctr = 6 cctr = 0 for f in os.listdir('to import'): print 'Processing file %s' % f with open('to import/' + f, 'r') as h: with open('export/' + f, 'w') as ex: if f.endswith('electricityrates.csv'): cctr += 1 # skip the first line h.readline() for line in h.readlines(): if not line.startswith(',') and not line == str(): ex.write(str(ctr) + ',' + line[0:-4] + '\n') #skip the last comma elif f.endswith('FuelPrice.csv'): cctr += 1 # skip the first line h.readline() for line in h.readlines(): ex.write(str(ctr) + ',' + line) elif f.endswith('ListOfHours.csv'): cctr += 1 # skip the first line h.readline() for line in h.readlines(): ex.write(str(ctr) + ',' + line) elif f.endswith('monthlydemandrates.csv'): cctr += 1 # skip the first line h.readline() for line in h.readlines(): if not line.startswith(',') and not line == str(): ex.write(str(ctr) + ',' + line) elif f.endswith('MonthlyFee.csv'): cctr += 1 for line in h.readlines(): ex.write(str(ctr) + ',' + line) elif f.endswith('monthseason.csv'): cctr += 1 # skip the first line h.readline() for line in h.readlines(): ex.write(str(ctr) + ',' + line) if cctr % 6 == 0: ctr += 1