Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import psycopg2, pandas as pd, numpy as np
- import datetime
- conn = psycopg2.connect(host="localhost", database="MIMIC2", user="student", password="hi")
- cur = conn.cursor()
- cur.execute(\"select charttime, itemid, value1num from mimic2v26.chartevents where icustay_id = 24 and itemid in (211, 52) order by 1, 2;")
- pt_data = pd.DataFrame(cur.fetchall(), columns=[col[0] for col in cur.description]) # get the header,
- cur.close()
- conn.close()
- # selects data from mimic database
- pt_data ['charttime'] = pt_data ['charttime'] - datetime.timedelta(1000*365) #subtract 1000 years from charttime
- pt_data = pt_data.pivot('charttime', 'itemid', 'value1num') #pivot the table
- pt_data.columns = ["Daily Median Heart Rate", "Daily Median MAP"]
- pt_data.index.names["Date"]
- #need to downsample
- #use forward fill for the empty sqaures - will have one NaN
- 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