Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- from os import listdir
- from os.path import isfile, join
- import re
- onlyfiles = [f for f in listdir(".") if isfile(join(".", f)) and f.lower().endswith('.csv')]
- familyname = []
- tekname = re.compile('[0-9]{6}_[0-9]{6}')
- for f in onlyfiles:
- if tekname.match(f):
- cutname = f[0:13]
- if not cutname in familyname and not isfile(cutname+".csv"):
- familyname.append(cutname)
- print("Going to generate the following: "+str(familyname))
- input("Ok? (ctrl+c to stop)")
- for file in familyname:
- print("Generating "+ file)
- input_files = [f for f in onlyfiles if file in f]
- print("Input files: "+str(input_files))
- newCSVdata = []
- first = True # we need to get x from somewhere!
- for f in input_files:
- csvfile = open(f)
- readCSV = csv.reader(csvfile, delimiter=',')
- x = []
- y = []
- for row in readCSV:
- x.append(row[3])
- y.append(row[4])
- if first:
- first = False
- newCSVdata.append(x)
- newCSVdata.append(y)
- csvfile.close()
- with open(file+".csv", "w", newline='') as new_csv:
- csvWriter = csv.writer(new_csv, delimiter=',')
- csvWriter.writerows([*zip(*newCSVdata)])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement