Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- from os import listdir
- from os.path import isfile, join
- #generate list of times(in minutes) where patients require mapping (Ex. 5 minutes, 10 minutes, etc.)
- times = [5,10,15,30,45,60,90,120,150,180,240]
- mypath = 'G:\Jefferson\MASTER Files\MASTER Tables\Patient Path Spreadsheets'
- #need all of the .csv files in folder: G:\Jefferson\MASTER Files\MASTER Tables\Patient Path Spreadsheets
- all_files = [l for l in listdir(mypath) if isfile(join(mypath,l)) ]
- logs = [l for l in all_files if l[-8:] == 'Copy.csv']
- print logs
- #going patient by patient, opening the .csv file and reading it in
- for patient in logs:
- fin = open(mypath+'\\'+patient,'r')
- values = {}
- #identify column headers
- headers = fin.readline().strip().split(',')
- print headers
- #identify each line; read in as dictionary item
- all_lines = []
- for line in fin:
- activity = line.strip().split(',')
- lines = dict(zip(headers,activity))
- # print lines
- print lines['TSA']
- all_lines.append(lines)
- all_lines = sorted(all_lines, key=lambda d: d["TSA"])
- new_lines = []
- idx = 0
- for t in times:
- while all_lines[idx]["TSA"] < t:
- idx += 1
- # all_lines[idx] is the row to copy
- cp = all_lines[idx]
- cp["WHATEVER"] = "value"
- new_lines.append(cp)
- all_lines.extend(new_lines)
- # write all_lines
- #close .csv file
- fin.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement