Skip to content

Instantly share code, notes, and snippets.

@f-ewald
Created October 22, 2015 16:55
Show Gist options
  • Save f-ewald/1193b137a57b23ac21d3 to your computer and use it in GitHub Desktop.
Save f-ewald/1193b137a57b23ac21d3 to your computer and use it in GitHub Desktop.
Combines files by filename into one
# file combiner
# combines csv files into one
import os
for f in os.listdir('export'):
print 'Processing file %s' % f
with open('export/' + f, 'r') as h:
filename = str()
if f.endswith('electricityrates.csv'):
filename = 'electricityrates.csv'
elif f.endswith('FuelPrice.csv'):
filename = 'FuelPrice.csv'
elif f.endswith('ListOfHours.csv'):
filename = 'ListOfHours.csv'
elif f.endswith('monthlydemandrates.csv'):
filename = 'monthlydemandrates.csv'
elif f.endswith('MonthlyFee.csv'):
filename = 'MonthlyFee.csv'
elif f.endswith('monthseason.csv'):
filename = 'monthseason.csv'
with open('combined/' + filename, 'a') as export:
for l in h.readlines():
export.write(l)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment