@anonymous/WetAnyBunny
Python3

No description

repl talk
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#This script merges csv files within a folder.  It assumes all files have the same field names.  Note, older files may not have the actionId field
import csv
from os import listdir
from os.path import isfile, join

mypath = r"P:\Performance & Data\1 Data\3 TOMS Data\2017-09" #filepath to folder to be opened

onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
with open(r"P:\Performance & Data\1 Data\3 TOMS Data\2017-09" + r"\\" + "Summary.csv", 'wb') as myfile: #output file path
  fieldnames = ["inventoryId",	"ticketId",	"actionId","ticketSerialNbr",	"applicationId",	"eventDateTime",	"latitude",	"longitude",	"ridesRemaining",	"type",	"revenueMonth",	"tomsReferenceId",	"origin",	"destination",	"line",	"zone_pair",	"ticket_type"]
  wr = csv.DictWriter(myfile, quoting=csv.QUOTE_ALL, fieldnames=fieldnames)
  wr.writeheader()
  for f in onlyfiles:
    print(f)
    with open(mypath + r"\\" + f,'rb') as csvfile:
      spamreader = csv.DictReader(csvfile)
      for row in spamreader:
        wr.writerow(row) 
 
Python 3.6.1 (default, Dec 2015, 13:05:11) [GCC 4.8.2] on linux