Advertisement
Guest User

Assignment 3

a guest
Nov 7th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import psycopg2, pandas as pd, numpy as np
  2. import datetime
  3. conn = psycopg2.connect(host="localhost", database="MIMIC2", user="student", password="hi")
  4. cur = conn.cursor()
  5. cur.execute(\"select charttime, itemid, value1num from mimic2v26.chartevents where icustay_id = 24 and itemid in (211, 52) order by 1, 2;")
  6. pt_data = pd.DataFrame(cur.fetchall(), columns=[col[0] for col in cur.description]) # get the header,
  7. cur.close()
  8. conn.close()
  9.  
  10. # selects data from mimic database
  11. pt_data ['charttime'] = pt_data ['charttime'] - datetime.timedelta(1000*365) #subtract 1000 years from charttime
  12.  
  13.  
  14. pt_data = pt_data.pivot('charttime', 'itemid', 'value1num') #pivot the table
  15. pt_data.columns = ["Daily Median Heart Rate", "Daily Median MAP"]
  16. pt_data.index.names["Date"]
  17.  
  18. #need to downsample
  19. #use forward fill for the empty sqaures - will have one NaN
  20. pt_data.resample('d', how='median').ffill() #or is it charttime or datetime.charttime - datetime is everything
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement