Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. import math
  2. from os import listdir
  3. from os.path import isfile, join
  4.  
  5. #generate list of times(in minutes) where patients require mapping (Ex. 5 minutes, 10 minutes, etc.)
  6.  
  7. times = [5,10,15,30,45,60,90,120,150,180,240]
  8. mypath = 'G:\Jefferson\MASTER Files\MASTER Tables\Patient Path Spreadsheets'
  9.  
  10. #need all of the .csv files in folder: G:\Jefferson\MASTER Files\MASTER Tables\Patient Path Spreadsheets
  11. all_files = [l for l in listdir(mypath) if isfile(join(mypath,l)) ]
  12. logs = [l for l in all_files if l[-8:] == 'Copy.csv']
  13. print logs
  14.  
  15. #going patient by patient, opening the .csv file and reading it in
  16. for patient in logs:
  17. fin = open(mypath+'\\'+patient,'r')
  18. values = {}
  19. #identify column headers
  20. headers = fin.readline().strip().split(',')
  21. print headers
  22. #identify each line; read in as dictionary item
  23. all_lines = []
  24. for line in fin:
  25. activity = line.strip().split(',')
  26. lines = dict(zip(headers,activity))
  27. # print lines
  28. print lines['TSA']
  29. all_lines.append(lines)
  30.  
  31. all_lines = sorted(all_lines, key=lambda d: d["TSA"])
  32.  
  33. new_lines = []
  34. idx = 0
  35.  
  36. for t in times:
  37. while all_lines[idx]["TSA"] < t:
  38. idx += 1
  39. # all_lines[idx] is the row to copy
  40. cp = all_lines[idx]
  41. cp["WHATEVER"] = "value"
  42. new_lines.append(cp)
  43.  
  44. all_lines.extend(new_lines)
  45.  
  46. # write all_lines
  47.  
  48.  
  49. #close .csv file
  50. fin.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement